home *** CD-ROM | disk | FTP | other *** search
/ Sampler of Digital Rock Core Information / Sampler of Digital Rock Core Information Open File Report 91-355.ISO / source / coremap.c next >
Encoding:
C/C++ Source or Header  |  1992-01-06  |  113.5 KB  |  5,167 lines

  1. /*  
  2.  
  3.     mapper.c  3/15/89
  4.     updated  12/14/90
  5.  
  6.     mpp1.bat = cl /AL mapper.c vmaputil vimage2 dispio paradise
  7.  
  8.     by Russell A. Ambroziak, Ph. D.
  9.  
  10.     command line options:
  11.  
  12.     /e = EGA
  13.     /v = VGA 640x480x16 colors
  14.     /s = VGA 320x200x256 colors
  15.     /y = Extended VGA 640x400x256 colors
  16.     /x = Extended VGA 640x480x256 colors
  17.  
  18.     /l [path][file_name].[file_type] = output '.LAB' file of points
  19.     /o [path][file_name].[file_type] = output run information file
  20.     /a [path][file_name] = automatic map load on start
  21.     /p [program_name] = passes control to program from point (S)earch
  22.  
  23. */
  24. #include <conio.h>
  25. #include <stdio.h>
  26. #include <math.h>
  27. #include <string.h>
  28. #include "font.h"
  29. #include <process.h>
  30. #include <stdlib.h>
  31. #include <errno.h>
  32.  
  33. #define VGA 0
  34. /*#define NUMBER9  9*/
  35. #define MAX_X 640
  36. /*#define MAX_X 1024*/
  37. #define MENUXC 550
  38. /*#define MENUXC 950*/
  39. /*#define COREOFF 0*/
  40.  
  41. #define DEG_RAD 0.01745329251                /* converts degrees to radians */
  42. #define MAXDO 1000
  43. #define MAX_COLORS 16
  44. #define STR_LEN 100
  45. #define MIN_PIX  0.000
  46. #define TYPE 'p'
  47.  
  48. #define BLACK     0
  49. #define D_GREY    1
  50. #define L_GREY    2
  51. #define WHITE     3
  52. #define BUFF      4
  53. #define L_BUFF    5
  54. #define BROWN     6
  55. #define RED       7
  56. #define ORANGE    8
  57. #define YELLOW    9
  58. #define GREEN    10
  59. #define D_GREEN  11
  60. #define VD_GREEN 12
  61. #define BLUE     13
  62. #define D_BLUE   14
  63. #define MAGENTA  15
  64.  
  65. #define NUM_TYPE 25
  66. #define NUM_SIZE 25
  67. #define NUM_PSIZE 3
  68. #define NUM_FILL  5
  69. #define NUM_SYM  25
  70.  
  71. #define MENU_M  13
  72. #define MENU_L   8
  73. #define MENU_P   6
  74. #define MENU_IV  2
  75. #define SYM_SIZE 11
  76. #define NUM_DP 100
  77. #define B_LINES 48
  78.  
  79. #define F_SIZE 20
  80. #define NAME_SIZE 100
  81. #define S_SIZE 40
  82. #define T_SIZE 15
  83. #define MAX_NUM 300
  84. #define NUM_IMAGE 2
  85.  
  86. char *Menu_iv[MENU_IV]=
  87.     {"zoom",
  88.     "exit image"
  89. };
  90. struct   Color 
  91.     unsigned char  r, g, b; 
  92. }lutc[256],luts[256]; 
  93. int Black=0,White=191,Center=128,Num_Color=256;
  94. int D_Grey=46,L_Grey=191,M_Grey=128;
  95. struct Color Blk={  0,  0,  0};
  96. struct Color D_G={ 46, 46, 46};
  97. struct Color M_G={127,127,127};
  98. struct Color L_G={191,191,191};
  99. struct Color Wht={255,255,255};
  100. unsigned char ActiveLut;
  101. int Img=0,Sample=1,Xc=0,Yc=0,Speed=16,Row,Col,ZoomSample=1;
  102. char *SubType;
  103. struct equipment
  104. {
  105.     int printers;         /* number present */
  106.     int sprinter;        /* serial printer installed?  0=no  1=yes */
  107.     int game;            /* game adapter installed? */
  108.     int sports;            /* number of serial ports */
  109.     int dma;                /* DMA chip installed? */
  110.     int drives;            /* number of disk drives */
  111.     int video;            /* video mode 1=40 color 2=80 color 3=80 B/W */
  112.     int disk;            /* any disk drives? */
  113.     int memory;            /* memory size in Kbytes */
  114. };
  115. extern struct equipment Eq;
  116. extern int GF_Order[MAX_NUM];
  117. extern char GF_String[MAX_NUM][S_SIZE];
  118. struct file_id
  119. {
  120.     char name[S_SIZE];
  121.     long size;
  122.     unsigned date,time;
  123. };
  124. extern struct file_id GF_File[MAX_NUM];
  125. extern int Monitor;
  126. char DepthFile[100]={"colo.dpt"};
  127. float D1[MAX_NUM],D2[MAX_NUM];
  128. struct image_header
  129. {
  130.     int row,col;
  131.     int sample;
  132.     int record_bytes,file_records;
  133.     int record_col_header;
  134.     int row_col_header;
  135.     int header_bytes;
  136.     int imbedded_header;
  137.     int sample_bits;
  138.     char infile[100],image[100],Lut[100],pal_type,label[100];
  139.     int vga_color[256];
  140.     struct Color lut[256],lutc[256];
  141. }Hdr[NUM_IMAGE];
  142.  
  143. int Sym_Size=SYM_SIZE;
  144. char LastMap[STR_LEN],LastFile[STR_LEN],Auto=0;
  145. char *Exit={"exit"};
  146. float BackBright=1.0;
  147. int NumPath=1;
  148. char Path[NUM_DP][STR_LEN];
  149. char String[STR_LEN];
  150. char String[STR_LEN];
  151. int RawOn;
  152. int FontSize=2;
  153. float PixScale;
  154. char Suffix[20];
  155. FILE *FpLab;
  156. char VideoType='X';
  157. int MaxXs,MaxYs;
  158. char Disk_Dir[100];
  159. char *Menu_V[NUM_TYPE+3];
  160. char *Menu_P[NUM_SYM+3];
  161. char *Menu_M[MENU_M]=
  162. {
  163.     "zoom",                        /*  0 */
  164.     "overlays ON/OFF",        /*  1 */
  165.     "reset",                        /*  2 */
  166.     "Change projection",        /*  3 */
  167.     "Save map",                    /*  4 */
  168.     "Recall map",                /*  5 */
  169.     "cursor mode",                /*  6 */
  170.     "vector plot",                /*  7 */
  171.     "annotate",                    /*  8 */
  172.     "draw lines",                /*  9 */
  173.     "graticule",                /* 10 */
  174.     "point plot",                /* 11 */
  175.     "exit"
  176. };
  177. /*
  178.       0 -- red
  179.      18 -- orange
  180.      34 -- yellow-orange
  181.      50 -- yellow
  182.      68 -- yellow-green
  183.      85 -- green
  184.      95 -- green-cyan
  185.     105 -- cyan
  186.     125 -- blue-cyan
  187.     144 -- blue
  188.     167 -- blue-purple
  189.     190 -- purple
  190.     206 -- magenta-purple
  191.     223 -- magenta
  192.     240 -- red-magenta
  193.     255 -- red
  194. */
  195. unsigned char MaxHues[256][3]=
  196. {
  197. 255,  0,  0,255, 32,  0,255, 42,  0,255, 53,  0,255, 60,  0,255, 68,  0,
  198. 255, 73,  0,255, 80,  0,255, 84,  0,255, 90,  0,255, 94,  0,255,100,  0,
  199. 255,103,  0,255,108,  0,255,112,  0,255,116,  0,255,121,  0,255,124,  0,
  200. 255,128,  0,255,132,  0,255,135,  0,255,139,  0,255,143,  0,255,146,  0,
  201. 255,150,  0,255,154,  0,255,157,  0,255,161,  0,255,164,  0,255,168,  0,
  202. 255,172,  0,255,176,  0,255,179,  0,255,183,  0,255,186,  0,255,190,  0,
  203. 255,194,  0,255,198,  0,255,202,  0,255,206,  0,255,210,  0,255,214,  0,
  204. 255,218,  0,255,222,  0,255,227,  0,255,231,  0,255,236,  0,255,241,  0,
  205. 255,245,  0,255,250,  0,254,255,  0,249,255,  0,244,255,  0,240,255,  0,
  206. 234,255,  0,229,255,  0,224,255,  0,220,255,  0,214,255,  0,209,255,  0,
  207. 204,255,  0,199,255,  0,194,255,  0,190,255,  0,184,255,  0,179,255,  0,
  208. 174,255,  0,169,255,  0,164,255,  0,158,255,  0,152,255,  0,147,255,  0,
  209. 141,255,  0,135,255,  0,130,255,  0,123,255,  0,116,255,  0,109,255,  0,
  210. 102,255,  0, 94,255,  0, 87,255,  0, 78,255,  0, 68,255,  0, 58,255,  0,
  211.  42,255,  0, 23,255,  0,  0,255, 36,  0,255, 58,  0,255, 73,  0,255, 87,
  212.   0,255,101,  0,255,113,  0,255,125,  0,255,135,  0,255,146,  0,255,156,
  213.   0,255,166,  0,255,176,  0,255,186,  0,255,196,  0,255,204,  0,255,214,
  214.   0,255,224,  0,255,233,  0,255,243,  0,255,252,  0,248,255,  0,239,255,
  215.   0,230,255,  0,222,255,  0,214,255,  0,207,255,  0,200,255,  0,194,255,
  216.   0,187,255,  0,181,255,  0,174,255,  0,169,255,  0,163,255,  0,157,255,
  217.   0,152,255,  0,146,255,  0,141,255,  0,136,255,  0,131,255,  0,126,255,
  218.   0,121,255,  0,116,255,  0,111,255,  0,106,255,  0,101,255,  0, 96,255,
  219.   0, 92,255,  0, 86,255,  0, 81,255,  0, 77,255,  0, 71,255,  0, 66,255,
  220.   0, 60,255,  0, 53,255,  0, 48,255,  0, 39,255,  0, 32,255,  0, 23,255,
  221.   0,  0,255, 16,  0,255, 23,  0,255, 28,  0,255, 32,  0,255, 36,  0,255,
  222.  39,  0,255, 42,  0,255, 45,  0,255, 48,  0,255, 50,  0,255, 53,  0,255,
  223.  58,  0,255, 60,  0,255, 62,  0,255, 64,  0,255, 66,  0,255, 68,  0,255,
  224.  70,  0,255, 73,  0,255, 75,  0,255, 77,  0,255, 78,  0,255, 81,  0,255,
  225.  83,  0,255, 84,  0,255, 87,  0,255, 89,  0,255, 92,  0,255, 93,  0,255,
  226.  94,  0,255, 97,  0,255, 98,  0,255,101,  0,255,103,  0,255,105,  0,255,
  227. 107,  0,255,109,  0,255,111,  0,255,113,  0,255,115,  0,255,117,  0,255,
  228. 119,  0,255,122,  0,255,124,  0,255,126,  0,255,129,  0,255,131,  0,255,
  229. 134,  0,255,135,  0,255,138,  0,255,140,  0,255,143,  0,255,145,  0,255,
  230. 148,  0,255,151,  0,255,154,  0,255,156,  0,255,160,  0,255,163,  0,255,
  231. 166,  0,255,169,  0,255,173,  0,255,176,  0,255,179,  0,255,183,  0,255,
  232. 188,  0,255,192,  0,255,196,  0,255,200,  0,255,204,  0,255,209,  0,255,
  233. 214,  0,255,220,  0,255,225,  0,255,231,  0,255,237,  0,255,244,  0,255,
  234. 250,  0,255,255,  0,252,255,  0,245,255,  0,238,255,  0,231,255,  0,224,
  235. 255,  0,217,255,  0,210,255,  0,203,255,  0,196,255,  0,190,255,  0,183,
  236. 255,  0,176,255,  0,170,255,  0,163,255,  0,156,255,  0,151,255,  0,144,
  237. 255,  0,137,255,  0,131,255,  0,125,255,  0,118,255,  0,112,255,  0,105,
  238. 255,  0, 98,255,  0, 90,255,  0, 83,255,  0, 77,255,  0, 68,255,  0, 60,
  239. 255,  0, 50,255,  0, 42,255,  0, 28,255,  0, 23
  240. };
  241. char T_Menu_L[NUM_TYPE+3][2][50];
  242. char *T_Menu_P[MENU_P+3][2];
  243. float MaxLat,MinLat,MaxLon,MinLon;
  244. FILE *Fpout;
  245. char SaveName[100]={"mapper.out"};
  246. double ll[MAXDO][2];
  247. int todo[2][MAXDO];
  248. unsigned char MT_Buff[12][MAX_X],Mbuff[B_LINES][MAX_X],Buffer[MAX_X];
  249. long MT_Buff_size=7680,Mbuff_size=30720;
  250. unsigned char Inbuff[BUFSIZ],Inbuff2[BUFSIZ],Outbuff[BUFSIZ];
  251. int SaveVec=0,SNum=1;
  252. int ScreenXs,ScreenYs;
  253. struct board
  254. {
  255.     int row,col,color;
  256. }B_Id;
  257. struct map_screen
  258. {
  259.     int xc,yc,xs,ys;
  260. }map_pos;
  261. struct map_input
  262. {
  263.     char *name,type;
  264.     double indat[6];
  265. }miv;
  266. struct symbol_name
  267. {
  268.     char name[50],filename[50];
  269.     float max_pix,min_pix;
  270.     int color;
  271.     char on;
  272.     char Symbol[SYM_SIZE][SYM_SIZE];
  273. }PlaceFile[NUM_SYM];
  274. struct map
  275. {
  276.     int KeyPlotted;
  277.     char Fill_Name[256][20];
  278.     int Fill_In;
  279.     int Fill_After;
  280.     int Fill_Color[256][2];
  281.     int Max_Fill;
  282.     int Fill_Color_RGB[256][3];
  283.     float Fill_Color_IHS[256][3];
  284.     int Fill_Order[256];
  285.     int Comp_Color[256];
  286.     int Num_Fill;
  287.     float FI_min[NUM_FILL],FI_max[NUM_FILL];
  288.     char Fill_In_Name[NUM_FILL][STR_LEN];
  289.     int White,Num_Color;
  290.     int screen_xs,screen_ys;
  291.     int Num_Type,Out;
  292.     float Pixsize,Clat,Clon,Space;
  293.     int Mback,Text,High,Back,Grat;
  294.     int GratOn;
  295.     int LatLon,Black;
  296.     char Color_Name[MAX_COLORS][30];
  297.     int Color_Val[MAX_COLORS][3];
  298.     int Type;
  299.     int Ns[NUM_TYPE];
  300.     int Mm[NUM_TYPE];
  301.     int NumSymbol;
  302.     int Dummy1;
  303.     int Dummy2;
  304.     char Group_Name[NUM_TYPE][30];
  305.     struct line_name
  306.     {
  307.         char filename[54];
  308.         float max_pix,min_pix;
  309.         int color;
  310.     }MapFile[NUM_TYPE][NUM_SIZE];
  311.     struct place_name
  312.     {
  313.         char *name,*filename;
  314.         float max_pix,min_pix;
  315.         int color;
  316.     }PlaceFile[3][3];    /* size = 18*3*3 = 162 bytes */
  317.     struct Color lut[256];
  318. }M;
  319.  
  320. unsigned char getpt();
  321.  
  322. int fill_in();
  323. int auto_fill_in();
  324. void pix_loc();
  325. int check_point();
  326. int purge();
  327. void remove_boundaries();
  328. void fill_voids();
  329. void set_lut();
  330. int load_miv();
  331. void screen_mm();
  332. int do_menu(char *[],int,int,int,int,int,int,int,int [128][25]); 
  333. int t_do_menu();
  334. int plot_map();
  335. void get_corners();
  336. int tplot_line();
  337. int unplot_line();
  338. char Zoom();
  339. int convert_bin();
  340. int read_control();
  341. int get_color();
  342. char fsplit(char *,char *,char *,char *);
  343. FILE *open_to_read_binary(char *);
  344. FILE *open_to_write_text(char *);
  345. FILE *open_to_write_binary(char *);
  346.  
  347. main(argc,argv)
  348.  
  349. int argc;
  350. char *argv[];
  351.  
  352. {
  353.     int i,j,k,p;
  354.     char ans,ans2,cfile[100],string[100];
  355.     int mt=0,lbrite=64,nbrite=127,brite;
  356.     int cx=256,cy=ScreenYs/2;
  357.     int xc,yc,xs,ys,ix,iy,val,speed,isize=FontSize,color;
  358.     float pixsize=12.0,clat=38.0,clon=-95.75,space=10.0;
  359.     int m_num=0,plotmap=0;
  360.     FILE *fp;
  361.     int point=0;
  362.  
  363.     ix=ScreenXs/2;
  364.     iy=ScreenYs/2;
  365.     speed=16;
  366.  
  367.     for(i=0;i<argc;i++)
  368.     {
  369.         if(argv[i][1]==':')
  370.             add_disk_path(argv[i]);
  371.         if(argv[i][0]=='/'&&argv[i][1]=='a')
  372.         {
  373.             Auto=1;
  374.             strcpy(LastMap,argv[i+1]);
  375.         }
  376.         if(argv[i][0]=='/'&&argv[i][1]=='o')
  377.         {
  378.             if(M.Out==0&&i<argc-1)
  379.             {
  380.                 add_disk_path(argv[i+1]);
  381.                 Fpout=fopen(argv[i+1],"wt");
  382.                 if(Fpout)
  383.                 {
  384.                     M.Out=1;
  385.                     printf("Output file = '%s'\n",argv[i+1]);
  386.                 }
  387.                 else
  388.                 {
  389.                     printf("Could not open '%s' to write.\n\n",argv[i+1]);
  390.                     M.Out=0;
  391.                     printf("HIT ANY KEY TO CONTINUE!\n\n");
  392.                     getch();
  393.                 }
  394.             }
  395.         }
  396.         if(argv[i][0]=='/'&&argv[i][1]=='l')
  397.         {
  398.             FpLab=fopen(argv[i+1],"wt");
  399.             if(FpLab)
  400.             {
  401.                 printf("Label Output file = '%s'\n",argv[i+1]);
  402.                 printf("HIT ANY KEY TO CONTINUE!\n\n");
  403.                 getch();
  404.             }
  405.             else
  406.             {
  407.                 printf("Could not open '%s' to write.\n\n",argv[i+1]);
  408.                 printf("HIT ANY KEY TO CONTINUE!\n\n");
  409.                 getch();
  410.             }
  411.         }
  412.         if(argv[i][0]=='/'&&(argv[i][1]=='e'||argv[i][1]=='E'))
  413.         {
  414.             ScreenYs=380;
  415.             cy=ScreenYs/2;
  416.         }
  417.         if(argv[i][0]=='/'&&argv[i][1]=='R')
  418.             RawOn=1;
  419.         if(argv[i][0]=='/'&&(argv[i][1]=='X'||argv[i][1]=='x'))
  420.             VideoType='X';
  421.         if(argv[i][0]=='/'&&(argv[i][1]=='Y'||argv[i][1]=='y'))
  422.             VideoType='Y';
  423.         if(argv[i][0]=='/'&&(argv[i][1]=='E'||argv[i][1]=='e'))
  424.             VideoType='E';
  425.         if(argv[i][0]=='/'&&(argv[i][1]=='V'||argv[i][1]=='v'))
  426.             VideoType='V';
  427.         if(argv[i][0]=='/'&&(argv[i][1]=='S'||argv[i][1]=='s'))
  428.             VideoType='S';
  429.         if(argv[i][0]=='/'&&(argv[i][1]=='g'||argv[i][1]=='G'))
  430.             M.GratOn=1;
  431.     }
  432.     xc=0;yc=0;xs=ScreenXs;ys=ScreenYs;
  433.     video_on();
  434. /* use SubPaths with type of SubType for sub images */
  435.                                     /* move all Path up 1 */
  436.     for(i=NumPath;i>0;i--)
  437.         strcpy(Path[i],Path[i-1]);
  438.     NumPath+=1;
  439.                                     /* add '?mp\' to a new set of Paths */
  440.     for(i=1;i<NumPath;i++)
  441.         sprintf(Path[NumPath+i-1],"%s%s\\",Path[i],SubType+1);
  442.     NumPath+=NumPath-1;
  443.  
  444. /*
  445. SetVideoMode(0);
  446. for(i=0;i<NumPath;i++)
  447. printf("%2d -- '%s'\n",i,Path[i]);
  448. exit(0);
  449. */
  450.  
  451.     M.Pixsize*=PixScale;
  452.     pixsize=M.Pixsize;
  453.     clat=M.Clat;
  454.     clon=M.Clon;
  455.     space=M.Space;    
  456.     cy=ScreenYs/2;
  457.     SetVideoMode(0);
  458.     if(Auto==1&&strlen(LastMap)>0)
  459.     {
  460.         video_on();
  461.         strcat(LastMap,Suffix);
  462.         if(unsave_map(LastMap)>0)
  463.         {
  464.             plotmap=1;
  465.             ix=ScreenXs/2;
  466.             iy=ScreenYs/2;
  467.             speed=16;
  468.             m_num=6;
  469.             pix_loc(ix,iy,&ix,&iy,&speed);
  470.         }
  471.         else
  472.             SetVideoMode(0);
  473.     }
  474.     if(plotmap==0)
  475.     {
  476.         printf("     Choose a map to start with\n");
  477.         printf("by using the up and down arrow\n");
  478.         printf("keys, 'Pg Up' or 'Pg Dn' keys,\n");
  479.         printf("or by typing the name of the\n");
  480.         printf("map.  Hit 'Enter' to select a\n");
  481.         printf("map.  If the map is not in this\n");
  482.         printf("directory and you have entered\n");
  483.         printf("command line path names, hit\n");
  484.         printf("'Esc' to continue on to other\n");
  485.         printf("paths.\n\n");
  486.         printf("     If you wish to draw a map\n");
  487.         printf("rather than load one that is\n");
  488.         printf("already drawn -- hit 'Esc'\n");
  489.         printf("until the menu contains '*.map'\n");
  490.         printf("files.\n\n");
  491.         printf("     If you copy drawn map\n");
  492.         printf("files from one disc to another,\n");
  493.         printf("the path names may be incorrect\n");
  494.         printf("and you may not be able to\n");
  495.         printf("zoom.\n");
  496.         plotmap=0;
  497.         sprintf(string,"*%s",Suffix);
  498.         if(search_list(string,cfile)>=0)
  499.         {
  500.             video_on();
  501.             unsave_map(cfile);
  502.             plotmap=1;
  503.         }
  504.     }
  505.     if(plotmap==0)
  506.     {
  507.         if(search_list("*.map",cfile)<0)
  508.         {
  509.             printf("No maps chosen.\n\n");
  510.             exit(0);
  511.         }
  512.         if(strlen(cfile)>0)
  513.             val=read_control(cfile);
  514.         else
  515.             exit(0);
  516.         if(val<0)
  517.         {
  518.             if(val==-1)
  519.                 printf("Could not open control file '%s'\n\n",cfile);
  520.             if(val==-2)
  521.                 printf("Could not find 'begin_color in file '%s'\n\n",cfile);
  522.             if(val==-3)
  523.                 printf("Could not find 'begin_vector in file '%s'\n\n",cfile);
  524.             if(val==-4)
  525.                 printf("Too many vectors in a group in file '%s'\n\n",cfile);
  526.             if(val==-5)
  527.                 printf("Bad color name in file '%s'\n\n",cfile);
  528.             if(val==-6)
  529.     printf
  530.     ("Missing or bad pixel size, central lat and lon or graticule spacing\n");
  531.             exit(0);
  532.         }
  533.         video_on();
  534.         M.Pixsize*=PixScale;
  535.         pixsize=M.Pixsize;
  536.         clat=M.Clat;
  537.         clon=M.Clon;
  538.         space=M.Space;    
  539.         cy=ScreenYs/2;
  540.         set_lut('c',0);
  541.         plot_map(xc,yc,ScreenXs,ScreenYs,pixsize,clat,clon,space,0);
  542.     }
  543.     do
  544.     {
  545.         m_num=M_do_menu(Menu_M,MENU_M,MENUXC,25,m_num,M.Mback,M.Text,M.High,Font);
  546.         if(m_num==0)
  547.         {
  548.             pixsize=M.Pixsize;
  549.             clat=M.Clat;
  550.             clon=M.Clon;
  551.             space=M.Space;
  552.             ans=Zoom(xc,yc,ScreenXs,ScreenYs,&pixsize,&clat,&clon,&space);
  553.             if(ans!=27)
  554.             plot_map(xc,yc,ScreenXs,ScreenYs,pixsize,clat,clon,space,0);
  555.         }
  556.         if(m_num==1)
  557.         {
  558.             pixsize=M.Pixsize;
  559.             clat=M.Clat;
  560.             clon=M.Clon;
  561.             space=M.Space;
  562.             T_do_menu(T_Menu_L,M.Num_Type+3,25,25,m_num,M.Mback,M.Text,M.High,
  563.                     Font,M.Mm);
  564.             plot_map(xc,yc,ScreenXs,ScreenYs,pixsize,clat,clon,space,0);
  565.         }
  566.         if(m_num==2)
  567.         {
  568.             xc=0;yc=0;xs=ScreenXs;ys=ScreenYs;
  569.             pixsize=M.Pixsize;
  570.             clat=M.Clat;
  571.             clon=M.Clon;
  572.             space=M.Space;
  573.             plot_map(xc,yc,ScreenXs,ScreenYs,pixsize,clat,clon,space,0);
  574.         }
  575.         if(m_num==3)
  576.         {
  577.             pixsize=M.Pixsize;
  578.             clat=M.Clat;
  579.             clon=M.Clon;
  580.             space=M.Space;
  581.             save_box(0,M.Black,Mbuff,0,MaxYs-40,MaxXs,40);
  582.             sprintf(String,"Give new projection type.  l=Lambert  a=Albers");
  583.             if(VideoType=='S')
  584.                 plot_font_h(M.White,5,MaxYs-38,String,3,Font);
  585.             else
  586.                 plot_font_h(M.White,5,MaxYs-38,String,2,Font);
  587.             sprintf(String,
  588. "'m'=Mercator  's'=polar stereographic  'p'=plate carre   S=sinusoidal");
  589.             if(VideoType=='S')
  590.                 plot_font_h(M.White,5,MaxYs-18,String,3,Font);
  591.             else
  592.                 plot_font_h(M.White,5,MaxYs-18,String,2,Font);
  593.             M.Type=getch();
  594.             if(M.Type=='l'||M.Type=='a'||
  595.                     M.Type=='m'||M.Type=='s'||M.Type=='p'||M.Type=='S')
  596.                 plot_map(xc,yc,ScreenXs,ScreenYs,pixsize,clat,clon,space,0);
  597.             else
  598.             {
  599.                 M.Type='p';
  600.                 unsave_box(0,M.Black,Mbuff,0,MaxYs-40,MaxXs,40);
  601.             }
  602.         }
  603.         if(m_num==4)
  604.         {
  605.             i=0;
  606.             do
  607.             {
  608.                 fclose(fp);
  609.                 sprintf(string,"mapper%02d%s",i++,Suffix);
  610.                 fp=open_to_read_binary(string);
  611.             }while(fp);
  612.             fclose(fp);
  613.             save_map(string);
  614.         }
  615.         if(m_num==5)
  616.         {
  617.             sprintf(string,"*%s",Suffix);
  618.             SetVideoMode(0);
  619.             if(search_list(string,cfile)>=0)
  620.             {
  621.                 video_on();
  622.                 unsave_map(cfile);
  623.             }
  624.             else
  625.             {
  626.                 printf("No maps chosen.\n\n");
  627.                 exit(0);
  628.             }
  629.         }
  630.         if(m_num==6)
  631.         {
  632.             ix=ScreenXs/2;
  633.             iy=ScreenYs/2;
  634.             speed=16;
  635.             pix_loc(ix,iy,&ix,&iy,&speed);
  636.         }
  637.         if(m_num==7)
  638.         {
  639.             pixsize=M.Pixsize;
  640.             vector_plot(pixsize);
  641.         }
  642.         if(m_num==8)
  643.         {
  644.             ix=ScreenXs/2;
  645.             iy=ScreenYs/2;
  646.             isize=FontSize;
  647.             color=M.White;
  648.             while(annotate(&ix,&iy,&isize,&color)!=27);
  649.         }
  650.         if(m_num==9)
  651.         {
  652.             ix=ScreenXs/2;
  653.             iy=ScreenYs/2;
  654.             color=M.White;
  655.             while(draw_line(&ix,&iy,&color)!=27);
  656.         }
  657.         if(m_num==10)
  658.             add_graticule();
  659.         if(m_num==11)
  660.             point=point_plot(M.Pixsize,point);
  661.     }while(m_num!=MENU_M-1); 
  662.  
  663.     SetVideoMode(0);
  664.     fclose(Fpout);
  665.     fclose(FpLab);
  666. }
  667.  
  668. /********************************************************************
  669. **
  670. **    locate a point
  671. **
  672. ********************************************************************* */
  673.  
  674. void pix_loc(fx,fy,px,py,sp)
  675.  
  676. int fx,fy;            /* starting point of cursor */
  677. int *px,*py,*sp;        /* pointers to final location */
  678.  
  679. {
  680.     int i,j,l,m,p;
  681.     int ans,size=0,speed,x,y,xo,yo,k,ans2,ans3,screen_xs=ScreenXs;
  682.     static unsigned char tbuff[200];
  683.     int lsize=FontSize,val,ival,val1,val2;
  684.     char string[100],pth[STR_LEN],nam[10],typ[10];
  685.     int idc[2],clr,num;
  686.     double lat,lon;
  687.     FILE *fpblb;
  688.     double dx,dy;
  689.     int ix,iy,color=M.White,xc,txs,cspeed=8,tcolor[3];
  690.     float fspeed=0.05;
  691.     float pixsize=M.Pixsize;
  692.     long lxs,lys,buffersize=(long)B_LINES*(long)MAX_X;
  693.  
  694.     if(VideoType=='S')
  695.         lsize=3;
  696.     ScreenXs=MaxXs;
  697.     speed=*sp;
  698.     size=0;
  699.     xo=x=fx;
  700.     yo=y=fy;
  701.     tcursor(0,x,y,5,tbuff);
  702.     lxs=42*15/lsize;
  703.     lys=32/lsize;
  704.     if(lxs*lys>buffersize)
  705.     {
  706.         printf("Box 1 too large in 'pix_loc()'\n");
  707.         exit(0);
  708.     }
  709.     lxs=MaxXs;
  710.     lys=32/lsize;
  711.     if(lxs*lys>buffersize)
  712.     {
  713.         printf("Box 2 too large in 'pix_loc()'\n");
  714.         exit(0);
  715.     }
  716.     save_box(0,M.Back,Mbuff,
  717.         0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
  718.     while((ans=getpad(&size,&x,&y,&speed,0))!=27&&ans!=13)
  719.     {
  720.         if(ans=='h'||ans=='H'||ans==59)        /* F1 */
  721.         {
  722.             txs=ScreenXs;
  723.             unsave_box(0,M.Back,Mbuff,
  724.                 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
  725.             save_box(0,M.Back,Mbuff,
  726.                 0,0,MaxXs,32/lsize);
  727.             paint_box(0,M.Back,MT_Buff,0,0,ScreenXs,32/lsize);
  728.             if(VideoType=='X'||VideoType=='S'||VideoType=='Y')
  729.             {
  730.                 sprintf(string,
  731. "(k)ey  (K)ey  (n)ame 1  (N)ame all  (P)aint area  (R)emove lines");
  732.                 plot_font_h(M.White,1,1,string,FontSize,Font);
  733.                 if(getch()==0)
  734.                     getch();
  735.                 if(M.Fill_In>0)
  736.                 {
  737.                     paint_box(0,M.Back,MT_Buff,0,0,ScreenXs,32/lsize);
  738.                     sprintf(string,"(D)arker map colors  (B)righter map colors");
  739.                     plot_font_h(M.White,1,1,string,FontSize,Font);
  740.                     if(getch()==0)
  741.                         getch();
  742.                 }
  743.                 paint_box(0,M.Back,MT_Buff,0,0,ScreenXs,32/lsize);
  744.                 sprintf(string,
  745. "(E)dit colors  (C)olor table output  (f)lash");
  746.             }
  747.             else
  748.                 sprintf(string,
  749. "(k)ey  (K)ey  (n)ame 1  (N)ame all  (P)aint area");
  750.             plot_font_h(M.White,1,1,string,FontSize,Font);
  751.             if(getch()==0)
  752.                 getch();
  753.             if(M.NumSymbol>0)
  754.             {
  755.                 paint_box(0,M.Back,MT_Buff,0,0,ScreenXs,32/lsize);
  756. #ifdef COREOFF
  757. sprintf(string,"(i)ndex points");
  758. #else
  759. sprintf(string,"(l)abel points   (i)ndex points");
  760. #endif
  761.                 plot_font_h(M.White,1,1,string,FontSize,Font);
  762.                 getch();
  763.                 paint_box(0,M.Back,MT_Buff,0,0,ScreenXs,32/lsize);
  764. sprintf(string,"(S)earch for nearest point  e(x)it to picture");
  765.                 plot_font_h(M.White,1,1,string,FontSize,Font);
  766.                 getch();
  767.                 paint_box(0,M.Back,MT_Buff,0,0,ScreenXs,32/lsize);
  768.             }
  769.             unsave_box(0,M.Back,Mbuff,
  770.                 0,0,MaxXs,32/lsize);
  771.             save_box(0,M.Back,Mbuff,
  772.                 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
  773.             screen_xs=txs;
  774.         }
  775.         uncursor(0,xo,yo,5,tbuff);
  776.         val=getpt(0,x,y)-16;
  777.         color=M.Comp_Color[val+16];
  778.         tcursor(0,x,y,5,tbuff);
  779.         cursor(0,x,y,color,5);
  780.         dx=xo=x;
  781.         dy=yo=y;
  782.         xy_ll(dx,dy,&lat,&lon);
  783. #ifdef COREOFF
  784.         if(ans=='l')
  785.         {
  786.             for(i=0;i<M.NumSymbol;i++)
  787.             {
  788.                 if(PlaceFile[i].on==1&&
  789.                     pixsize>=PlaceFile[i].min_pix&&pixsize<PlaceFile[i].max_pix)
  790.                 {
  791.                     symbol_plot(i,1);
  792.                 }
  793.             }
  794.         }
  795. #endif
  796.         if(ans=='i')
  797.         {
  798.             for(i=0;i<M.NumSymbol;i++)
  799.             {
  800.                 if(PlaceFile[i].on==1&&
  801.                     pixsize>=PlaceFile[i].min_pix&&pixsize<PlaceFile[i].max_pix)
  802.                 {
  803.                     symbol_plot(i,2);
  804.                 }
  805.             }
  806.         }
  807.         if(ans=='m')
  808.         {
  809.             cursor(0,x,y,M.White,5);
  810.             tcursor(0,x,y,5,tbuff);
  811.             cursor(0,x,y,M.White,5);
  812.             if(M.Out==1&&Fpout)
  813.                 fprintf(Fpout,"%10.6lf %11.6lf\n",lat,lon);
  814.         }
  815.         paint_box(0,M.Back,MT_Buff,0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
  816.         if(val>0)
  817.         {
  818.             sprintf(string,"%3d %s %9.6lf %11.6lf",val,M.Fill_Name[val],lat,lon);
  819.             if(strlen(string)>65)
  820.             {
  821.                 printf("string too long -- strlen(string) = %d\n",strlen(string));
  822.                 exit(0);
  823.             }
  824.         }
  825.         else
  826.         {
  827.             sprintf(string,"        %9.6lf %11.6lf",lat,lon);
  828.             if(strlen(string)>65)
  829.             {
  830.                 printf("string too long -- strlen(string) = %d\n",strlen(string));
  831.                 exit(0);
  832.             }
  833.         }
  834.         plot_font_h(M.White,2,ScreenYs-30/lsize,string,lsize,Font);
  835.         if(ans=='n'&&(VideoType=='X'||VideoType=='S'||VideoType=='Y'))
  836.         {
  837.             uncursor(0,xo,yo,5,tbuff);
  838.             if(val>=0&&strlen(M.Fill_Name[val])>0)
  839.                 plot_font_h(color,x-strlen(M.Fill_Name[val])*15/lsize/2,y-13/lsize,
  840.                     M.Fill_Name[val],lsize,Font);
  841.             tcursor(0,x,y,5,tbuff);
  842.             cursor(0,x,y,color,5);
  843.             xo=x;yo=y;
  844.         }
  845.         if(ans=='D'&&(BackBright>0.11))
  846.         {
  847.             BackBright-=0.10;
  848.             set_back();
  849.         }
  850.         if(ans=='B'&&(BackBright<2.0))
  851.         {
  852.             BackBright+=0.10;
  853.             set_back();
  854.         }
  855.         if(ans=='P')
  856.         {
  857.             unsave_box(0,M.Back,Mbuff,
  858.                 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
  859.             uncursor(0,xo,yo,5,tbuff);
  860.             i=0;
  861.             while((string[i++]=getch())!=13);
  862.             string[i]='\0';
  863.             sscanf(string,"%d",&clr);    
  864.             if(clr>=0&&clr<=M.Max_Fill)
  865.             {
  866.                 dx=xo;dy=yo;
  867.                 xy_ll(dx,dy,&lat,&lon);
  868.                 if(FpLab)
  869.                     fprintf(FpLab,"   0     0  %9.6lf %11.6lf %3d %3d\n",
  870.                         lat,lon,clr,clr);
  871.                 if(VideoType=='X'||VideoType=='S'||VideoType=='Y')
  872.                     auto_fill_in(0,clr+16,MT_Buff,todo,xo,yo);
  873.                 else
  874.                 {
  875.                     val1=M.Fill_Color[clr][0];
  876.                     val2=M.Fill_Color[clr][1];
  877.                     if(val1==M.Back)
  878.                         val1=M.Black;
  879.                     if(val2==M.Back)
  880.                         val2=M.Black;
  881.                     auto_fill_in_2(0,val1,val2,Mbuff,todo,xo,yo);
  882.                 }
  883.             }
  884.             tcursor(0,xo,yo,5,tbuff);
  885.             save_box(0,M.Back,Mbuff,
  886.                 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
  887.             cursor(0,xo,yo,color,5);
  888.         }
  889.         if(ans=='p'&&(VideoType=='X'||VideoType=='S'||VideoType=='Y'))
  890.         {
  891.             uncursor(0,xo,yo,5,tbuff);
  892.             clr=getpt(0,xo,yo)-16;
  893.             dx=xo;dy=yo;
  894.             xy_ll(dx,dy,&lat,&lon);
  895.             if(FpLab)
  896.                 fprintf(FpLab,"   0     0  %9.6lf %11.6lf %3d %3d\n",
  897.                     lat,lon,clr,clr);
  898.             tcursor(0,xo,yo,5,tbuff);
  899.             cursor(0,xo,yo,color,5);
  900.         }
  901.         if(ans=='f'||ans=='F')
  902.         {
  903.             tcolor[0]=M.lut[val+16].r;
  904.             tcolor[1]=M.lut[val+16].g;
  905.             tcolor[2]=M.lut[val+16].b;
  906.             M.lut[val+16].r=255;
  907.             M.lut[val+16].g=255;
  908.             M.lut[val+16].b=255;
  909.             WritePalette(M.lut);
  910.             M.lut[val+16].r=tcolor[0];
  911.             M.lut[val+16].g=tcolor[1];
  912.             M.lut[val+16].b=tcolor[2];
  913.             if(getch()==0)
  914.                 getch();
  915.             WritePalette(M.lut);
  916.         }
  917.         if(ans=='E'&&val>0) /* edit colors */
  918.         {
  919.             unsave_box(0,M.Back,Mbuff,
  920.                 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
  921.             save_box(0,M.Back,Mbuff,
  922.                 0,ScreenYs-64/lsize,20*15/lsize,64/lsize);
  923.             do
  924.             {
  925.                 paint_box(0,M.Back,MT_Buff,0,ScreenYs-64/lsize,
  926.                     20*15/lsize,64/lsize);
  927.                 sprintf(String,"I=%4.2f H=%3.0f S=%4.2f",
  928.                     M.Fill_Color_IHS[val][0],M.Fill_Color_IHS[val][1],
  929.                     M.Fill_Color_IHS[val][2]);
  930.                 plot_font_h(M.White,1,ScreenYs-64/lsize+1,String,lsize,Font);
  931.                 sprintf(String," %4.2f    %3d   %4.2f",fspeed,cspeed,fspeed*2.0);
  932.                 plot_font_h(M.White,1,ScreenYs-32/lsize+1,String,lsize,Font);
  933.                 ans2=getch();
  934.                 if(ans2=='-')
  935.                 {
  936.                     if(cspeed>1)
  937.                         cspeed/=2;
  938.                     if(fspeed>0.01)
  939.                         fspeed/=2.0;
  940.                 }
  941.                 if(ans2=='+')
  942.                 {
  943.                     if(cspeed<64)
  944.                         cspeed*=2;
  945.                     if(fspeed<0.16)
  946.                         fspeed*=2.0;
  947.                 }
  948.                 if(ans2==0)
  949.                 {
  950.                     ans3=getch();
  951.                     if(ans3==71)
  952.                         M.Fill_Color_IHS[val][0]+=fspeed;
  953.                     if(ans3==79)
  954.                         M.Fill_Color_IHS[val][0]-=fspeed;
  955.                     if(M.Fill_Color_IHS[val][0]>1.0)
  956.                         M.Fill_Color_IHS[val][0]=1.0;
  957.                     if(M.Fill_Color_IHS[val][0]<0.0)
  958.                         M.Fill_Color_IHS[val][0]=0.0;
  959.                     if(ans3==73)
  960.                         M.Fill_Color_IHS[val][2]+=fspeed*2.0;
  961.                     if(ans3==81)
  962.                         M.Fill_Color_IHS[val][2]-=fspeed*2.0;
  963.                     if(M.Fill_Color_IHS[val][2]>1.0)
  964.                         M.Fill_Color_IHS[val][2]=1.0;
  965.                     if(M.Fill_Color_IHS[val][2]<0.0)
  966.                         M.Fill_Color_IHS[val][2]=0.0;
  967.                     if(ans3==72)
  968.                         M.Fill_Color_IHS[val][1]+=cspeed;
  969.                     if(ans3==80)
  970.                         M.Fill_Color_IHS[val][1]-=cspeed;
  971.                     if(M.Fill_Color_IHS[val][1]>255)
  972.                         M.Fill_Color_IHS[val][1]-=256;
  973.                     if(M.Fill_Color_IHS[val][1]<0)
  974.                         M.Fill_Color_IHS[val][1]+=256;
  975.                     set_lut('c',1);
  976.                 }
  977.             }while(ans2!=27&&ans2!=13);
  978.             unsave_box(0,M.Back,Mbuff,
  979.                 0,ScreenYs-64/lsize,20*15/lsize,64/lsize);
  980.             save_box(0,M.Back,Mbuff,
  981.                 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
  982.         }
  983.         if(ans=='C')    /* print data in 'mapper.out' */
  984.             set_lut('c',0);
  985.         if(ans=='A')
  986.         {
  987.             for(i=0;i<ScreenYs;i++)
  988.             {
  989.                 for(j=0;j<ScreenXs;j++)
  990.                 {
  991.                     if((i+j)%2==0)
  992.                         MT_Buff[0][j]=(j*16)/ScreenXs;
  993.                     else
  994.                         MT_Buff[0][j]=(i*16)/ScreenYs;
  995.                 }
  996.                 plotrow(0,0,ScreenXs-1,i,MT_Buff[0]);
  997.             }
  998.         }
  999.         if(ans=='k'&&M.Fill_In>0)
  1000.         {
  1001.             ScreenXs=MaxXs;
  1002.             M.KeyPlotted=0;
  1003.             if(VideoType!='S')
  1004.                 plot_key(ScreenXs,0,3);
  1005.             else
  1006.                 plot_key(ScreenXs,0,4);
  1007.             screen_xs=ScreenXs;
  1008.             xy_ll((double)(ScreenXs/2),(double)(ScreenYs/2),&lat,&lon);
  1009.             miv.indat[0]=M.Pixsize;
  1010.             miv.indat[1]=M.Clat=lat;
  1011.             miv.indat[2]=M.Clon=lon;
  1012.             miv.indat[3]=M.Clon;
  1013.             miv.indat[4]=M.Clat+10;
  1014.             miv.indat[5]=M.Clat-10;
  1015.             map_pos.xc=0;    
  1016.             map_pos.yc=0;
  1017.             map_pos.xs=ScreenXs;
  1018.             map_pos.ys=ScreenYs;
  1019.             auto_set_cc(miv.type,miv.indat);
  1020.             ScreenXs=MaxXs;
  1021.         }
  1022.         if(ans=='K'&&M.Fill_In>0)
  1023.         {
  1024.             ScreenXs=MaxXs;
  1025.             M.KeyPlotted=0;
  1026.             if(VideoType!='S')
  1027.                 plot_key(ScreenXs,0,2);
  1028.             else
  1029.                 plot_key(ScreenXs,0,3);
  1030.             screen_xs=ScreenXs;
  1031.             xy_ll((double)(ScreenXs/2),(double)(ScreenYs/2),&lat,&lon);
  1032.             miv.indat[0]=M.Pixsize;
  1033.             miv.indat[1]=M.Clat=lat;
  1034.             miv.indat[2]=M.Clon=lon;
  1035.             miv.indat[3]=M.Clon;
  1036.             miv.indat[4]=M.Clat+10;
  1037.             miv.indat[5]=M.Clat-10;
  1038.             map_pos.xc=0;    
  1039.             map_pos.yc=0;
  1040.             map_pos.xs=ScreenXs;
  1041.             map_pos.ys=ScreenYs;
  1042.             auto_set_cc(miv.type,miv.indat);
  1043.             ScreenXs=MaxXs;
  1044.         }
  1045.         if(ans=='S'&&M.NumSymbol>0)
  1046.         {
  1047.             if(search_points(&x,&y,M.Pixsize,string)>0)
  1048.             {
  1049.                 paint_box(0,M.Back,MT_Buff,
  1050.                         0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
  1051.                 uncursor(0,xo,yo,5,tbuff);
  1052.                 val=getpt(0,x,y)-16;
  1053.                 color=M.Comp_Color[val+16];
  1054.                 tcursor(0,x,y,5,tbuff);
  1055.                 cursor(0,x,y,color,5);
  1056.                 xo=x;yo=y;
  1057.                 plot_font_h(M.White,2,ScreenYs-30/lsize,string,lsize,Font);
  1058.             }
  1059.         }
  1060.         if(ans=='x'&&M.NumSymbol>0)    /* look at pictures */
  1061.         {
  1062.             if(search_points(&x,&y,M.Pixsize,string)>0)
  1063.             {
  1064.                 picture_view(string);
  1065.                 if(unsave_map(LastMap)>0)
  1066.                 {
  1067.                     save_box(0,M.Back,Mbuff,
  1068.                         0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
  1069.                     uncursor(0,xo,yo,5,tbuff);
  1070.                     val=getpt(0,x,y)-16;
  1071.                     color=M.Comp_Color[val+16];
  1072.                     tcursor(0,x,y,5,tbuff);
  1073.                     cursor(0,x,y,color,5);
  1074.                     xo=x;yo=y;
  1075.                     plot_font_h(M.White,2,ScreenYs-30/lsize,string,lsize,Font);
  1076.                 }
  1077.             }
  1078.         }
  1079.         if(ans=='N')
  1080.         {
  1081.             unsave_box(0,M.Back,Mbuff,
  1082.                 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
  1083.             for(m=0;m<M.Num_Fill;m++)
  1084.             {
  1085.                 fpblb=open_to_read_binary(M.Fill_In_Name[m]);
  1086.                 if(fpblb)
  1087.                 {
  1088.                     while(fread((char *)idc,sizeof(int),2,fpblb)==2)
  1089.                     {
  1090.                         fread((char *)&lat,sizeof(double),1,fpblb);
  1091.                         fread((char *)&lon,sizeof(double),1,fpblb);
  1092.                         ll_xy(&dx,&dy,lat,lon);
  1093.                         ix=dx;iy=dy;
  1094.                         if(ix>=0&&ix<ScreenXs&&iy>=0&&iy<ScreenYs)
  1095.                         {
  1096.                             ival=idc[1];
  1097.                             color=M.Comp_Color[ival+16];
  1098.                             if(ival>0)
  1099.                             {
  1100.                                 if(strlen(M.Fill_Name[ival])>0)
  1101.                                     plot_font_h(color,
  1102.                                         ix-strlen(M.Fill_Name[ival])*15/lsize/2,
  1103.                                     iy-13/lsize,
  1104.                                     M.Fill_Name[ival],lsize,Font);
  1105.                             }
  1106.                         }
  1107.                     }
  1108.                 }
  1109.             }
  1110.             fclose(fpblb);
  1111.             save_box(0,M.Back,Mbuff,
  1112.                 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
  1113.         }
  1114.         if(ans=='R'&&(VideoType=='X'||VideoType=='S'||VideoType=='Y'))
  1115.         {
  1116.             unsave_box(0,M.Back,Mbuff,
  1117.                 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
  1118.             remove_boundaries(M.MapFile[0][0].color);
  1119.             save_box(0,M.Back,Mbuff,
  1120.                 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
  1121.         }
  1122.         xo=x;yo=y;
  1123.     }
  1124.     uncursor(0,xo,yo,5,tbuff);
  1125.     unsave_box(0,M.Back,Mbuff,
  1126.         0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
  1127.     *px=x;*py=y;*sp=speed;
  1128.     ScreenXs=screen_xs;
  1129.     return;
  1130. }
  1131.  
  1132.  
  1133. /***********************************************************************
  1134. **
  1135. **
  1136. **
  1137. **
  1138. ************************************************************************/
  1139.  
  1140. int picture_view(string)
  1141.  
  1142. char *string;
  1143.  
  1144. {
  1145.     int i,j,k;
  1146.     char filename[STR_LEN],str1[50],str2[50],str3[50],str4[50];
  1147.     int ans;
  1148.     FILE *fp;
  1149.     char instring[STR_LEN],infile[STR_LEN];
  1150.  
  1151.     if(sscanf(string,"%s%s%s%s",str1,str2,str3,str4)<4)
  1152.         return(-1);
  1153.     sprintf(str1,"?%s*.lbl",str4);
  1154.     SetVideoMode(0);
  1155.  
  1156.     do
  1157.     {
  1158.         SetCursor(0,0);
  1159.         sprintf(infile,"%s.doc",str4);
  1160.         fp=fopen(infile,"rt");
  1161.         if(fp)
  1162.         {
  1163.             while(fgets(instring,80,fp)!=NULL)
  1164.                 printf("%s",instring);
  1165.         }
  1166.         fclose(fp);
  1167.         ans=D_get_file_name(str1,filename);
  1168.         if(ans<0)
  1169.         {
  1170.             video_on();
  1171.             return(1);
  1172.         }
  1173.         strcpy(Hdr[Img].label,filename);
  1174.         for(k=0;k<strlen(filename);k++)
  1175.         if(filename[k]=='.')
  1176.             filename[k]='\0';
  1177.         strcpy(string,filename);
  1178.         strcat(string,".lbl");        
  1179.         if(read_lbl(Hdr[Img].label,Img)>0)
  1180.         {
  1181.             fcloseall();
  1182.             video_on();
  1183.             process_image(Img);
  1184.             SetVideoMode(0);            
  1185.         }
  1186.     }while(ans>=0);
  1187.     video_on();
  1188. }
  1189.  
  1190. /**************************************************************************
  1191. **
  1192. **
  1193. **
  1194. ************************************************************************* */
  1195.  
  1196. int process_image(filenum)
  1197.  
  1198. int filenum;
  1199.  
  1200. {
  1201.     int num=0;
  1202.     int ix=ScreenXs/2,iy=ScreenYs/2,speed=16;
  1203.     int meni_iv=0;
  1204.  
  1205.     load_image(filenum);    
  1206.     do
  1207.     {
  1208.         num=M_do_menu(Menu_iv,MENU_IV,MENUXC,25,num,D_Grey,L_Grey,White,Font);
  1209.         if(num==0)
  1210.         {
  1211.             load_image(filenum);            
  1212.         }
  1213.     }while(num<MENU_IV-1);
  1214.     ZoomSample=1;
  1215. }
  1216.  
  1217. /**************************************************************************
  1218. **
  1219. **
  1220. **
  1221. ************************************************************************* */
  1222.  
  1223. int load_image(filenum)
  1224.  
  1225. int filenum;
  1226.  
  1227. {
  1228.     int i,j,k;
  1229.     int sample=0;
  1230.     int xs,ys;
  1231.     FILE *fp;
  1232.     long offset=0;
  1233.     char string[100];
  1234.  
  1235.     Row=Hdr[filenum].row;
  1236.     Col=Hdr[filenum].col;
  1237.     if(VideoType=='S')
  1238.         Speed=8;
  1239.  
  1240.     if(Hdr[filenum].sample_bits==0)
  1241.         Hdr[filenum].sample_bits=8;
  1242.  
  1243.     if((Row==0||Col==0)&&Hdr[filenum].row_col_header==0)
  1244.         return(-1);
  1245.     fp=open_to_read_binary(Hdr[filenum].image);
  1246.     if(!fp)
  1247.         return(-1);
  1248.     if(Hdr[filenum].row_col_header==1)
  1249.     {
  1250.         fread((char *)&Hdr[filenum].row,sizeof(int),1,fp);
  1251.         fread((char *)&Hdr[filenum].col,sizeof(int),1,fp);
  1252.         Col=Hdr[filenum].col;
  1253.         Row=Hdr[filenum].row;
  1254.         if(Row<=0||Col<=0)
  1255.             return(-1);
  1256.     }
  1257.     else if(Hdr[filenum].imbedded_header==1)
  1258.     {
  1259.         offset=Hdr[filenum].col;
  1260.         fseek(fp,offset,SEEK_SET);
  1261.     }
  1262.     else if(Hdr[filenum].header_bytes>0)
  1263.     {
  1264.         offset=Hdr[filenum].header_bytes;
  1265.         fseek(fp,offset,SEEK_SET);
  1266.     }
  1267.     video_on();
  1268.     do
  1269.     {
  1270.         Sample=sample+=1;
  1271.         Row=Hdr[filenum].row/sample;
  1272.         Col=Hdr[filenum].col/sample;
  1273.         offset=(sample-1);
  1274.         offset*=Hdr[filenum].col;
  1275.     }while(Col>ScreenXs||Row>ScreenYs);
  1276.     Hdr[filenum].sample=sample;
  1277.     if(Hdr[filenum].pal_type>0)
  1278.         IV_set_lut(Hdr[filenum].pal_type);
  1279.     else
  1280.     {
  1281.         if(IV_set_lut('P',Hdr[filenum].Lut)<0)
  1282.             IV_set_lut('G');
  1283.     }
  1284.     plot_full_image(fp,sample,filenum);
  1285.  
  1286.     if(sample>1)
  1287.     {
  1288.         sample=ZoomSample;
  1289.         if(limit_area_fixed(&Xc,&Yc,&xs,&ys,&Speed,&sample)!=27)
  1290.         {
  1291.             ZoomSample=sample;
  1292.             plot_sub_image(fp,sample,filenum);
  1293.         }
  1294.         else
  1295.         {
  1296.             ZoomSample=Sample;
  1297.         }
  1298.     }
  1299.     fclose(fp);
  1300. }
  1301.  
  1302. /********************************************************************
  1303. **
  1304. **    type  g -- grey all lut[] files
  1305. **            G -- grey only lut[]
  1306. **            i -- initial header map
  1307. **            r -- reset lut[] to lutc[]
  1308. **            p -- positive (0-127) magenta, negative (128-255) green
  1309. **
  1310. ********************************************************************* */
  1311.  
  1312. int IV_set_lut(type,filename)
  1313.  
  1314. char type,*filename;
  1315.  
  1316. {
  1317.     int i,k,hue,brite,j;
  1318.     int r,g,b;
  1319.     float color[3];
  1320.     double dbrite,dval;
  1321.     float val,minval,sat,inten;
  1322.     float fval,fk;
  1323.     FILE *fplut;
  1324.     int end=0,scale,sum;
  1325.     char string[100];
  1326.     long del,mindel,l1,l2,l3,l4;
  1327.  
  1328.     scale=1;
  1329.     if(Num_Color==16)
  1330.         scale=17;
  1331.     if(type=='P')
  1332.     {
  1333.         fplut=open_to_read_binary(filename);
  1334.         if(fplut)
  1335.         {
  1336.             i=0;
  1337.             do
  1338.             {
  1339.                 i+=1;
  1340.                 fscanf(fplut,"%s",string);
  1341.             }while(strcmpi(string,"end")!=0&&i<50);
  1342.             if(strcmpi(string,"end")!=0)
  1343.                 rewind(fplut);
  1344.             for(i=0;i<256;i++)
  1345.             {
  1346.                 fscanf(fplut,"%d%d%d%d",&k,&r,&g,&b);
  1347.                 Hdr[Img].lut[i].r=r;
  1348.                 Hdr[Img].lut[i].g=g;
  1349.                 Hdr[Img].lut[i].b=b;
  1350.             }
  1351.             fclose(fplut);
  1352.         }
  1353.         else
  1354.             return(-1);
  1355.         if(VideoType=='V'||VideoType=='E')
  1356.         {
  1357.             for(i=0;i<256;i++)
  1358.             {
  1359.                 sum=(int)Hdr[Img].lut[i].r*10;
  1360.                 sum+=(int)Hdr[Img].lut[i].g*8;
  1361.                 sum+=(int)Hdr[Img].lut[i].b*2;
  1362.                 sum/=319;
  1363.                 Hdr[Img].vga_color[i]=sum;
  1364.             }
  1365.             for(k=0;k<Num_Color;k++)
  1366.             {
  1367.                 Hdr[Img].lut[k].r=k*scale;
  1368.                 Hdr[Img].lut[k].g=k*scale;
  1369.                 Hdr[Img].lut[k].b=k*scale;
  1370.             }
  1371.         }
  1372.         ActiveLut='P';
  1373.     }
  1374.     if(type=='g')
  1375.     {
  1376.         for(k=0;k<Num_Color;k++)
  1377.         {
  1378.             Hdr[Img].lutc[k].r=Hdr[Img].lut[k].r=k*scale;
  1379.             Hdr[Img].lutc[k].g=Hdr[Img].lut[k].g=k*scale;
  1380.             Hdr[Img].lutc[k].b=Hdr[Img].lut[k].b=k*scale;
  1381.         }
  1382.         ActiveLut='g';
  1383.     }
  1384.     if(type=='G')
  1385.     {
  1386.         for(k=0;k<Num_Color;k++)
  1387.         {
  1388.             Hdr[Img].lut[k].r=k*scale;
  1389.             Hdr[Img].lut[k].g=k*scale;
  1390.             Hdr[Img].lut[k].b=k*scale;
  1391.         }
  1392.         ActiveLut='G';
  1393.     }
  1394.     if(type=='i')
  1395.     {
  1396.         for(k=0;k<Num_Color;k++)
  1397.         {
  1398.             Hdr[Img].lutc[k].r=Hdr[Img].lut[k].r=k*scale;
  1399.             Hdr[Img].lutc[k].g=Hdr[Img].lut[k].g=k*scale;
  1400.             Hdr[Img].lutc[k].b=Hdr[Img].lut[k].b=k*scale;
  1401.         }
  1402.         Hdr[Img].lut[ 64].r=  0;Hdr[Img].lut[ 64].g=  0;Hdr[Img].lut[ 64].b=128;
  1403.         Hdr[Img].lut[127].r=  0;Hdr[Img].lut[127].g=100;Hdr[Img].lut[127].b=  0;
  1404.         Hdr[Img].lut[191].r=255;Hdr[Img].lut[191].g=  0;Hdr[Img].lut[191].b=  0;
  1405.         Hdr[Img].lut[192].r=255;Hdr[Img].lut[192].g=128;Hdr[Img].lut[192].b=  0;
  1406.         Hdr[Img].lut[193].r=255;Hdr[Img].lut[193].g=255;Hdr[Img].lut[193].b=  0;
  1407.         Hdr[Img].lut[194].r=  0;Hdr[Img].lut[194].g=255;Hdr[Img].lut[194].b=  0;
  1408.         Hdr[Img].lut[195].r=  0;Hdr[Img].lut[195].g=255;Hdr[Img].lut[195].b=255;
  1409.         Hdr[Img].lut[196].r= 20;Hdr[Img].lut[196].g= 55;Hdr[Img].lut[196].b=255;
  1410.         Hdr[Img].lut[253].r=100;Hdr[Img].lut[253].g=  1;Hdr[Img].lut[253].b=  1;
  1411.         Hdr[Img].lut[254].r=100;Hdr[Img].lut[254].g=  1;Hdr[Img].lut[254].b=  1;
  1412.         ActiveLut='i';
  1413.     }
  1414.     if(type=='r')
  1415.     {
  1416.         for(k=0;k<Num_Color;k++)
  1417.         {
  1418.             Hdr[Img].lut[k].r=Hdr[Img].lutc[k].r;
  1419.             Hdr[Img].lut[k].g=Hdr[Img].lutc[k].g;
  1420.             Hdr[Img].lut[k].b=Hdr[Img].lutc[k].b;
  1421.         }
  1422.         ActiveLut='r';
  1423.     }
  1424.     mindel=16777216;
  1425.     for(i=0;i<Num_Color;i++)
  1426.     {
  1427.         l1=Blk.r;
  1428.         l2=Hdr[Img].lut[i].r;
  1429.         l3=Hdr[Img].lut[i].g;
  1430.         l4=Hdr[Img].lut[i].b;
  1431.         del=(l1-l2)*(l1-l2)+(l1-l3)*(l1-l3)+(l1-l4)*(l1-l4);
  1432.         if(del<mindel)
  1433.         {
  1434.             mindel=del;
  1435.             Black=i;
  1436.         }
  1437.     }
  1438.     mindel=16777216;
  1439.     for(i=0;i<Num_Color;i++)
  1440.     {
  1441.         l1=D_G.r;
  1442.         l2=Hdr[Img].lut[i].r;
  1443.         l3=Hdr[Img].lut[i].g;
  1444.         l4=Hdr[Img].lut[i].b;
  1445.         del=(l1-l2)*(l1-l2)+(l1-l3)*(l1-l3)+(l1-l4)*(l1-l4);
  1446.         if(del<mindel)
  1447.         {
  1448.             mindel=del;
  1449.             D_Grey=i;
  1450.         }
  1451.     }
  1452.     mindel=16777216;
  1453.     for(i=0;i<Num_Color;i++)
  1454.     {
  1455.         l1=M_G.r;
  1456.         l2=Hdr[Img].lut[i].r;
  1457.         l3=Hdr[Img].lut[i].g;
  1458.         l4=Hdr[Img].lut[i].b;
  1459.         del=(l1-l2)*(l1-l2)+(l1-l3)*(l1-l3)+(l1-l4)*(l1-l4);
  1460.         if(del<mindel)
  1461.         {
  1462.             mindel=del;
  1463.             M_Grey=i;
  1464.         }
  1465.     }
  1466.     mindel=16777216;
  1467.     for(i=0;i<Num_Color;i++)
  1468.     {
  1469.         l1=L_G.r;
  1470.         l2=Hdr[Img].lut[i].r;
  1471.         l3=Hdr[Img].lut[i].g;
  1472.         l4=Hdr[Img].lut[i].b;
  1473.         del=(l1-l2)*(l1-l2)+(l1-l3)*(l1-l3)+(l1-l4)*(l1-l4);
  1474.         if(del<mindel)
  1475.         {
  1476.             mindel=del;
  1477.             L_Grey=i;
  1478.         }
  1479.     }
  1480.     mindel=16777216;
  1481.     for(i=0;i<Num_Color;i++)
  1482.     {
  1483.         l1=Wht.r;
  1484.         l2=Hdr[Img].lut[i].r;
  1485.         l3=Hdr[Img].lut[i].g;
  1486.         l4=Hdr[Img].lut[i].b;
  1487.         del=(l1-l2)*(l1-l2)+(l1-l3)*(l1-l3)+(l1-l4)*(l1-l4);
  1488.         if(del<mindel)
  1489.         {
  1490.             mindel=del;
  1491.             White=i;
  1492.         }
  1493.     }
  1494.     WritePalette(Hdr[Img].lut);
  1495.     return(1);
  1496. }
  1497.  
  1498.  
  1499. /**************************************************************************
  1500. **
  1501. **
  1502. **
  1503. ************************************************************************* */
  1504.  
  1505. int plot_sub_image(fp,sample,filenum)
  1506.  
  1507. FILE *fp;
  1508. int sample,filenum;
  1509.  
  1510. {
  1511.     int i,j,k;
  1512.     long offset;
  1513.  
  1514.     rewind(fp);
  1515.     paint_box(3,0,Mbuff,0,0,ScreenXs,ScreenYs);
  1516.     offset=Hdr[filenum].col;
  1517.     offset*=Yc*Sample;
  1518.     offset+=Xc*Sample;
  1519.     if(Hdr[filenum].header_bytes>0)
  1520.         offset+=Hdr[filenum].header_bytes;
  1521.     fseek(fp,offset,SEEK_SET);
  1522.     Row=ScreenYs;
  1523.     Col=ScreenXs;
  1524.     if((Yc*Sample+Row*sample)>Hdr[filenum].row)
  1525.         Row=(Hdr[filenum].row-Yc*Sample)/sample;
  1526.     if((Xc*Sample+Col*sample)>Hdr[filenum].col)
  1527.         Col=(Hdr[filenum].col-Xc*Sample)/sample;
  1528.     offset=Hdr[filenum].col;
  1529.     offset*=(sample-1);
  1530.     for(i=0;i<Row;i++)
  1531.     {
  1532.         if(fread((char *)Mbuff[0],sizeof(char),Hdr[filenum].col,fp)<1)
  1533.         {
  1534.             return(-1);
  1535.         }
  1536.         fseek(fp,offset,SEEK_CUR);
  1537.         if(sample>1)
  1538.             for(j=0;j<Col;j++)
  1539.                 Mbuff[0][j]=Mbuff[0][j*sample];
  1540.         if(VideoType=='V'||VideoType=='E')
  1541.         {
  1542.             if(ActiveLut=='P')
  1543.             {
  1544.                 for(j=0;j<Col;j++)
  1545.                     Mbuff[0][j]=Hdr[filenum].vga_color[Mbuff[0][j]];
  1546.             }
  1547.             else
  1548.             {
  1549.                 for(j=0;j<Col;j++)
  1550.                     Mbuff[0][j]/=16;
  1551.             }
  1552.         }
  1553.         plotrow(3,0,Col-1,i,Mbuff[0]);
  1554.     }
  1555.  
  1556.     return(1);
  1557. }
  1558.  
  1559.  
  1560. /**************************************************************************
  1561. **
  1562. **
  1563. **
  1564. ************************************************************************* */
  1565.  
  1566. int plot_full_image(fp,sample,filenum)
  1567.  
  1568. FILE *fp;
  1569. int sample,filenum;
  1570.  
  1571. {
  1572.     int i,j,k;
  1573.     long offset;
  1574.     char string[100];
  1575.     int row,col;
  1576.     FILE *fpsub;
  1577.  
  1578.     strcpy(string,Hdr[filenum].image);
  1579.     for(i=0;i<strlen(string);i++)
  1580.         if(string[i]=='.')
  1581.             string[i]='\0';
  1582.     strcat(string,SubType);
  1583.     fpsub=open_to_read_binary(string);
  1584.     if(fpsub)
  1585.     {
  1586.         fread((char *)&row,sizeof(int),1,fpsub);
  1587.         fread((char *)&col,sizeof(int),1,fpsub);
  1588.         for(i=0;i<row;i++)
  1589.         {
  1590.             fread((char *)Mbuff[0],sizeof(char),col,fpsub);
  1591.             plotrow(0,0,col-1,i,Mbuff[0]);
  1592.         }
  1593.         fclose(fpsub);
  1594.     }
  1595.     else
  1596.     {
  1597.         rewind(fp);
  1598.         offset=Hdr[filenum].header_bytes;
  1599.         if(offset>0)
  1600.             fseek(fp,offset,SEEK_SET);
  1601.         offset=(sample-1);
  1602.         offset*=Hdr[filenum].col;
  1603.         for(i=0;i<Row;i++)
  1604.         {
  1605.             fread((char *)Mbuff[0],sizeof(char),Hdr[filenum].col,fp);
  1606.             if(offset>0)
  1607.                 fseek(fp,offset,SEEK_CUR);
  1608.             if(sample>1)
  1609.                 for(j=0;j<Col;j++)
  1610.                     Mbuff[0][j]=Mbuff[0][j*sample];
  1611.             if(VideoType=='V'||VideoType=='E')
  1612.             {
  1613.                 if(ActiveLut=='P')
  1614.                 {
  1615.                     for(j=0;j<Col;j++)
  1616.                         Mbuff[0][j]=Hdr[filenum].vga_color[Mbuff[0][j]];
  1617.                 }
  1618.                 else
  1619.                 {
  1620.                     for(j=0;j<Col;j++)
  1621.                         Mbuff[0][j]/=16;
  1622.                 }
  1623.             }
  1624.             plotrow(3,0,Col-1,i,Mbuff[0]);
  1625.         }
  1626.         if(sample>1)
  1627.         {
  1628.             fpsub=open_to_write_binary(string);
  1629.             if(fpsub)
  1630.             {
  1631.                 fwrite((char *)&Row,sizeof(int),1,fpsub);
  1632.                 fwrite((char *)&Col,sizeof(int),1,fpsub);
  1633.                 for(i=0;i<Row;i++)
  1634.                 {
  1635.                     getrow(0,0,Col-1,i,Mbuff[0]);
  1636.                     fwrite((char *)Mbuff[0],sizeof(char),Col,fpsub);
  1637.                 }
  1638.                 fclose(fpsub);
  1639.             }
  1640.         }
  1641.     }
  1642. }
  1643.  
  1644.  
  1645.  
  1646. /**************************************************************************
  1647. **
  1648. **
  1649. **
  1650. ************************************************************************* */
  1651.  
  1652. int limit_area_fixed(xc,yc,xs,ys,speed,sample)
  1653.  
  1654. int *xc,*yc,*xs,*ys,*speed,*sample;
  1655.  
  1656. {
  1657.     int i,j,k;
  1658.     int xco=*xc,yco=*yc,xso,yso;
  1659.     char ans;
  1660.  
  1661.     xso=*xs=ScreenXs/Sample*(*sample);
  1662.     yso=*ys=ScreenYs/Sample*(*sample);
  1663.  
  1664.     tbox_val(3,*xc,*yc,*xs,*ys,Mbuff,Black,White,Center);
  1665.     do
  1666.     {
  1667.         ans=getch();
  1668.         unbox(3,*xc,*yc,*xs,*ys,Mbuff);
  1669.         if(ans==27)
  1670.         {
  1671.             return(27);
  1672.         }
  1673.         else if(ans=='-'&&*speed>1)*speed/=2;
  1674.         else if(ans=='+'&&*speed<ScreenYs)*speed*=2;
  1675.         else if(ans=='l'&&*sample<Sample)
  1676.             *sample+=1;
  1677.         else if(ans=='s'&&*sample>1)
  1678.             *sample-=1;
  1679.         *xs=ScreenXs/Sample*(*sample);
  1680.         *ys=ScreenYs/Sample*(*sample);
  1681.  
  1682.         if(ans==0)
  1683.         {
  1684.             ans=getch();
  1685.             if(ans==71)
  1686.             {
  1687.                 *xc-=*speed;
  1688.                 *yc-=*speed;
  1689.             }
  1690.             else if(ans==73)
  1691.             {
  1692.                 *xc+=*speed;
  1693.                 *yc-=*speed;
  1694.             }
  1695.             else if(ans==79)
  1696.             {
  1697.                 *xc-=*speed;
  1698.                 *yc+=*speed;
  1699.             }
  1700.             else if(ans==81)
  1701.             {
  1702.                 *xc+=*speed;
  1703.                 *yc+=*speed;
  1704.             }
  1705.             else if(ans==72)
  1706.                 *yc-=*speed;
  1707.             else if(ans==80)
  1708.                 *yc+=*speed;
  1709.             else if(ans==75)
  1710.                 *xc-=*speed;
  1711.             else if(ans==77)
  1712.                 *xc+=*speed;
  1713.         }
  1714.         if(*xs>ScreenXs)*xs=ScreenXs;
  1715.         if(*ys>ScreenYs)*ys=ScreenYs;
  1716.         if(*xs<2)*xs=2;
  1717.         if(*ys<2)*ys=2;
  1718.         if((*xc+*xs)>=ScreenXs)*xc=ScreenXs-*xs;
  1719.         if((*yc+*ys)>=ScreenYs)*yc=ScreenYs-*ys;
  1720.         if(*xc<0)*xc=0;
  1721.         if(*yc<0)*yc=0;
  1722.         tbox_val(3,*xc,*yc,*xs,*ys,Mbuff,Black,White,Center);
  1723. }while(ans!=83&&ans!=27&&ans!=13);
  1724.     unbox(3,*xc,*yc,*xs,*ys,Mbuff);
  1725.     return(ans);
  1726. }
  1727.  
  1728.  
  1729. /**************************************************************************
  1730. **
  1731. **
  1732. **
  1733. ************************************************************************* */
  1734.  
  1735. int read_lbl(label,filenum)
  1736.  
  1737. char *label;
  1738. int filenum;
  1739.  
  1740. {
  1741.     int i,j,k;
  1742.     char string1[100],string2[100],string3[100];
  1743.     FILE *fp;
  1744.     int status=1,numread;
  1745.  
  1746.     fp=open_to_read_binary(label);
  1747.     if(!fp)
  1748.         return(-1);
  1749.     Hdr[filenum].sample_bits=Hdr[filenum].record_bytes=0;
  1750.     Hdr[filenum].file_records=0;
  1751.     Hdr[filenum].pal_type=0;
  1752.     Hdr[filenum].row_col_header=0;
  1753.     Hdr[filenum].Lut[0]='\0';
  1754.     while(fscanf(fp,"%s",string1)==1)
  1755.     {
  1756.         if(strcmpi(string1,"end")==0)
  1757.         {
  1758.             fclose(fp);
  1759.             return(status);
  1760.         }
  1761.         if(strcmpi(string1,"image_lines")==0&&Hdr[filenum].file_records==0)
  1762.         {
  1763.             numread=fscanf(fp,"%s%s",string2,string3);
  1764.             if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0||
  1765.                 numread<2)
  1766.             {
  1767.                 fclose(fp);
  1768.                 return(status);
  1769.             }            
  1770.             sscanf(string3,"%d",&Hdr[filenum].row);
  1771.             printf("Row = %d\n",Hdr[filenum].row);
  1772.         }
  1773.         if(strcmpi(string1,"sample_bits")==0)
  1774.         {
  1775.             numread=fscanf(fp,"%s%s",string2,string3);
  1776.             if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0||
  1777.                 numread<2)
  1778.             {
  1779.                 fclose(fp);
  1780.                 return(status);
  1781.             }            
  1782.             sscanf(string3,"%d",&Hdr[filenum].sample_bits);
  1783.             printf("Sample_Bits = %d\n",Hdr[filenum].sample_bits);
  1784.         }
  1785.         if(strcmpi(string1,"file_records")==0)
  1786.         {
  1787.             numread=fscanf(fp,"%s%s",string2,string3);
  1788.             if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0||
  1789.                 numread<2)
  1790.             {
  1791.                 fclose(fp);
  1792.                 return(status);
  1793.             }            
  1794.             sscanf(string3,"%d",&Hdr[filenum].row);
  1795.             printf("Row = %d\n",Hdr[filenum].row);
  1796.             Hdr[filenum].file_records=Hdr[filenum].row;
  1797.         }
  1798.         if(strcmpi(string1,"line_samples")==0&&Hdr[filenum].record_bytes==0)
  1799.         {
  1800.             numread=fscanf(fp,"%s%s",string2,string3);
  1801.             if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0||
  1802.                 numread<2)
  1803.             {
  1804.                 fclose(fp);
  1805.                 return(status);
  1806.             }            
  1807.             sscanf(string3,"%d",&Hdr[filenum].col);
  1808.             printf("Col = %d\n",Hdr[filenum].col);
  1809.         }
  1810.         if(strcmpi(string1,"record_bytes")==0||
  1811.             strcmpi(string1,"image_record_bytes")==0)
  1812.         {
  1813.             numread=fscanf(fp,"%s%s",string2,string3);
  1814.             if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0||
  1815.                 numread<2)
  1816.             {
  1817.                 fclose(fp);
  1818.                 return(status);
  1819.             }            
  1820.             sscanf(string3,"%d",&Hdr[filenum].col);
  1821.             printf("Col = %d\n",Hdr[filenum].col);
  1822.             Hdr[filenum].record_bytes=Hdr[filenum].col;
  1823.         }
  1824.         if(strcmpi(string1,"header_bytes")==0)
  1825.         {
  1826.             numread=fscanf(fp,"%s%s",string2,string3);
  1827.             if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0||
  1828.                 numread<2)
  1829.             {
  1830.                 fclose(fp);
  1831.                 return(status);
  1832.             }            
  1833.             sscanf(string3,"%d",&Hdr[filenum].header_bytes);
  1834.             printf("Header_Bytes = %d\n",Hdr[filenum].header_bytes);
  1835.         }
  1836.         if(strcmpi(string1,"image_pointer")==0)
  1837.         {
  1838.             numread=fscanf(fp,"%s%s",string2,string3);
  1839.             if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0||
  1840.                 numread<2)
  1841.             {
  1842.                 fclose(fp);
  1843.                 return(status);
  1844.             }            
  1845.             k=0;
  1846.             for(i=0;i<strlen(string3);i++)
  1847.                 if(string3[i]!=39)        /* single quote */
  1848.                     Hdr[filenum].image[k++]=string3[i];
  1849.             Hdr[filenum].image[k]='\0';
  1850.             printf("Image = %s\n",Hdr[filenum].image);
  1851.         }
  1852.         if(strcmpi(string1,"pal_type")==0)
  1853.         {
  1854.             numread=fscanf(fp,"%s%s",string2,string3);
  1855.             if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0||
  1856.                 numread<2)
  1857.             {
  1858.                 fclose(fp);
  1859.                 return(status);
  1860.             }            
  1861.             k=0;
  1862.             for(i=0;i<strlen(string3);i++)
  1863.                 if(string3[i]!=39)        /* single quote */
  1864.                     string1[k++]=string3[i];
  1865.             string1[k]='\0';
  1866.             Hdr[filenum].pal_type=string1[0];
  1867.             printf("Pal_Type = %c\n",Hdr[filenum].pal_type);
  1868.         }
  1869.         if(strcmpi(string1,"pal_pointer")==0)
  1870.         {
  1871.             numread=fscanf(fp,"%s%s",string2,string3);
  1872.             if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0||
  1873.                 numread<2)
  1874.             {
  1875.                 fclose(fp);
  1876.                 return(status);
  1877.             }            
  1878.             k=0;
  1879.             for(i=0;i<strlen(string3);i++)
  1880.                 if(string3[i]!=39)        /* single quote */
  1881.                     Hdr[filenum].Lut[k++]=string3[i];
  1882.             Hdr[filenum].Lut[k]='\0';
  1883.             printf("Lut = %s\n",Hdr[filenum].Lut);
  1884.         }
  1885.         if(strcmpi(string1,"row_col_header")==0)
  1886.         {
  1887.             numread=fscanf(fp,"%s%s",string2,string3);
  1888.             if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0||
  1889.                 numread<2)
  1890.             {
  1891.                 fclose(fp);
  1892.                 return(status);
  1893.             }            
  1894.             Hdr[filenum].row_col_header=1;
  1895.             Hdr[filenum].header_bytes=4;
  1896.         }
  1897.     }
  1898.     fclose(fp);
  1899.     return(status);
  1900. }
  1901.  
  1902.  
  1903.  
  1904. /********************************************************************
  1905. **
  1906. **        returns:
  1907. **
  1908. **            -3 -- too many files of type given
  1909. **            -2 -- no such files
  1910. **            -1 -- no file chosen
  1911. **          >=0 -- number of file chosen = n of String[n]
  1912. **
  1913. **
  1914. ********************************************************************* */
  1915.  
  1916. int D_get_file_name(file_id,file_name)
  1917.  
  1918. char *file_id,*file_name;
  1919.  
  1920. {
  1921.     int i,j,k;
  1922.     int num_files;
  1923.     int val=-2;
  1924.     char string[NAME_SIZE],file[F_SIZE],type[T_SIZE],directory[NAME_SIZE];
  1925.     int t=0,d=0,ls=-1;
  1926.     char s2[100];
  1927.  
  1928.     Monitor=check_equip(&Eq);
  1929.  
  1930.     for(i=0;i<strlen(file_id);i++)
  1931.         if(file_id[i]=='\\')
  1932.             ls=i;
  1933.     if(ls>0)
  1934.     {
  1935.         d=1;
  1936.         strcpy(directory,file_id);
  1937.         directory[ls+1]='\0';
  1938.     }
  1939.     else
  1940.         directory[0]='\0';
  1941.  
  1942.     num_files=D_load_File(file_id);
  1943.     if(num_files<0)
  1944.         return(num_files);
  1945.     else
  1946.     {
  1947.         ClearBox(40,79,0,0,112);
  1948.         sprintf(string," core id      Top (ft)  Bottom (ft)");
  1949.         WriteStringAtxy(40,0,39,(char)112,string);
  1950.         val=scroll_list(40,1,40,21,GF_String,num_files,file_name);
  1951.         if(val>=0)
  1952.         {
  1953.             strcpy(s2,file_name);
  1954.             sprintf(file_name,"%c%c%c%c%c%c%c%c.lbl",
  1955.                 s2[0],s2[2],s2[3],s2[4],s2[5],s2[7],s2[8],s2[9]);
  1956.         }    
  1957.     }
  1958.     return(val);
  1959. }
  1960.  
  1961. /********************************************************************
  1962. **
  1963. **    looks for a file named in a global char *DepthFile
  1964. **
  1965. **    format is:
  1966. **
  1967. **         filename   top_depth_in_feet   bottom_depth_in_feet
  1968. **
  1969. **   e.g.:
  1970. **
  1971. **       D356001   5472   5497
  1972. **       D356002   5497   5524
  1973. **       D356003   5524   5551
  1974. **       D356004   5551   5573
  1975. **
  1976. ********************************************************************* */
  1977.  
  1978. int D_load_File(instring)
  1979.  
  1980. char *instring;
  1981.  
  1982. {
  1983.     int i,i1;
  1984.     int num_files;
  1985.     int mo,da,yr,hr,min;
  1986.     char string[100],type[100],path[100];
  1987.     FILE *fpin;
  1988.     char name[100];
  1989.     float d1,d2;
  1990.  
  1991.     num_files=load_names(instring);
  1992.     if(num_files>=MAX_NUM)
  1993.         return(-3);
  1994.     if(num_files==0)
  1995.         return(-2);
  1996.     sort_name(num_files);
  1997.  
  1998.     fpin=open_to_read_binary(DepthFile);
  1999.     if(!fpin)
  2000.     {
  2001.         printf("Could not open '%s'\n",DepthFile);
  2002.         exit(0);
  2003.     }    
  2004.     for(i=0;i<num_files;i++)
  2005.     {
  2006.         i1=GF_Order[i];
  2007.         file_name(GF_File[i1].name,string,type);
  2008.         date_convert(GF_File[i1].date,&mo,&da,&yr);
  2009.         time_convert(GF_File[i1].time,&hr,&min);
  2010.         sprintf(GF_String[i],"%s %s%9ld %2d/%02d/%2d %02d%02d  "
  2011.             ,string,type,GF_File[i1].size,mo,da,yr,hr,min);
  2012.     }
  2013.     while(fscanf(fpin,"%s%f%f",name,&d1,&d2)==3)
  2014.     {
  2015.         for(i=0;i<num_files;i++)
  2016.         {
  2017.             i1=GF_Order[i];
  2018.             split(GF_File[i1].name,path,string,type);
  2019.             {
  2020.                 if(strcmpi(string,name)==0)
  2021.                 {
  2022.                     if(string[0]=='T'||string[0]=='t')
  2023.                         sprintf(GF_String[i],
  2024.                             "%c %c%c%c%c %c%c%c         %8.2f     ",
  2025.                             string[0],string[1],string[2],string[3],
  2026.                             string[4],string[5],string[6],string[7],d1);
  2027.                     else
  2028.                         sprintf(GF_String[i],
  2029.                             "%c %c%c%c%c %c%c%c    %5.0f     %5.0f   ",    
  2030.                             string[0],string[1],string[2],string[3],
  2031.                             string[4],string[5],string[6],string[7],d1,d2);
  2032.                     D1[i1]=d1;
  2033.                     D2[i1]=d2;
  2034.                 }
  2035.             }
  2036.         }
  2037.     }
  2038.     return(num_files);
  2039. }
  2040.  
  2041.  
  2042. /***********************************************************************
  2043. **
  2044. **
  2045. **
  2046. **
  2047. ************************************************************************/
  2048.  
  2049. int add_graticule()
  2050.  
  2051. {
  2052.     float pixsize=M.Pixsize;
  2053.     double sp;
  2054.  
  2055.     miv.type=M.Type;
  2056.     miv.indat[0]=pixsize;
  2057.     miv.indat[1]=M.Clat;
  2058.     miv.indat[2]=M.Clon;
  2059.     miv.indat[3]=M.Clon;
  2060.     miv.indat[4]=M.Clat+10;
  2061.     miv.indat[5]=M.Clat-10;
  2062.     map_pos.xc=0;    
  2063.     map_pos.yc=0;
  2064.     map_pos.xs=ScreenXs;
  2065.     map_pos.ys=ScreenYs;
  2066.     auto_set_cc(miv.type,miv.indat);
  2067.     screen_mm();
  2068.  
  2069.     if(pixsize>5.0)
  2070.     {
  2071.         sp=10;
  2072.         plot_graticule(Font,M.Grat,M.LatLon,sp,M.GratOn);
  2073.     }
  2074.     if(pixsize>2.5&&pixsize<=5.0)
  2075.     {
  2076.         sp=5;
  2077.         plot_graticule(Font,M.Grat,M.LatLon,sp,M.GratOn);
  2078.     }
  2079.     if(pixsize<=2.5&&pixsize>0.5)
  2080.     {
  2081.         sp=1;
  2082.         plot_graticule(Font,M.Grat,M.LatLon,sp,M.GratOn);
  2083.     }
  2084.     if(pixsize<=0.5&&pixsize>0.25)
  2085.     {
  2086.         sp=0.5;                                    
  2087.         plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
  2088.     }
  2089.     if(pixsize<=0.25&&pixsize>0.05)
  2090.     {
  2091.         sp=0.1;
  2092.         plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
  2093.     }
  2094.     if(pixsize<=0.05&&pixsize>0.025)
  2095.     {
  2096.         sp=0.05;
  2097.         plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
  2098.     }
  2099.     if(pixsize<=0.025&&pixsize>0.005)
  2100.     {
  2101.         sp=0.01;
  2102.         plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
  2103.     }
  2104.     if(pixsize<=0.005&&pixsize>0.0025)
  2105.     {
  2106.         sp=0.005;
  2107.         plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
  2108.     }
  2109.     if(pixsize<=0.0025)
  2110.     {
  2111.         sp=0.001;
  2112.         plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
  2113.     }
  2114. }
  2115.  
  2116.  
  2117.  
  2118. /***********************************************************************
  2119. **
  2120. **
  2121. **
  2122. **
  2123. ************************************************************************/
  2124.  
  2125. FILE *open_to_write_text(name)
  2126.  
  2127. char *name;
  2128.  
  2129. {
  2130.     int i,j,k;
  2131.     FILE *fp;
  2132.     char string[STR_LEN];
  2133.  
  2134.     for(j=0;j<NumPath;j++)
  2135.     {
  2136.         sprintf(string,"%s%s",Path[j],name);
  2137.         fp=fopen(string,"wt");
  2138.         if(fp)
  2139.         {
  2140.             strcpy(LastFile,name);
  2141.             return(fp);
  2142.         }
  2143.     }
  2144.     clearerr(fp);
  2145.     fp=NULL;
  2146.     return(fp);
  2147. }
  2148.  
  2149. /***********************************************************************
  2150. **
  2151. **
  2152. **
  2153. **
  2154. ************************************************************************/
  2155.  
  2156. FILE *open_to_write_binary(name)
  2157.  
  2158. char *name;
  2159.  
  2160. {
  2161.     int i,j,k;
  2162.     FILE *fp;
  2163.     char string[STR_LEN];
  2164.  
  2165.     for(j=0;j<NumPath;j++)
  2166.     {
  2167.         sprintf(string,"%s%s",Path[j],name);
  2168.         fp=fopen(string,"wb");
  2169.         if(fp)
  2170.         {
  2171.             strcpy(LastFile,name);
  2172.             return(fp);
  2173.         }
  2174.     }
  2175.     clearerr(fp);
  2176.     fp=NULL;
  2177.     return(fp);
  2178. }
  2179.  
  2180.  
  2181. /***********************************************************************
  2182. **
  2183. **
  2184. **
  2185. **
  2186. ************************************************************************/
  2187.  
  2188. FILE *open_to_read_binary(name)
  2189.  
  2190. char *name;
  2191.  
  2192. {
  2193.     int i,j,k;
  2194.     FILE *fp;
  2195.     char string[STR_LEN];
  2196.     int len;
  2197.  
  2198.     string[0]='\0';
  2199.     for(j=0;j<NumPath;j++)
  2200.     {
  2201.         len=strlen(Path[j])+strlen(name);
  2202.         if(len>0&&len<STR_LEN);
  2203.         {
  2204.             sprintf(string,"%s%s",Path[j],name);
  2205.             fp=fopen(string,"rb");
  2206.             if(fp)
  2207.             {
  2208.                 strcpy(LastFile,name);
  2209.                 return(fp);
  2210.             }    
  2211.         }
  2212.     }
  2213.     clearerr(fp);
  2214.     fp=NULL;
  2215.     return(fp);
  2216. }
  2217.  
  2218. /**************************************************************************
  2219. **
  2220. **
  2221. **
  2222. ************************************************************************* */
  2223.  
  2224. int add_disk_path(string)
  2225.  
  2226. char *string;
  2227.  
  2228. {
  2229.     int i,j,k;
  2230.     char dsk,pth[STR_LEN],nam[10],typ[10],str[STR_LEN];
  2231.     int match,add=0;
  2232.  
  2233.     dsk=fsplit(string,pth,nam,typ);
  2234.     if(dsk>0)
  2235.         sprintf(str,"%c:%s",dsk,pth);
  2236.     else
  2237.         sprintf(str,"%s",pth);
  2238.     if((dsk>0||strlen(pth)>0)&&NumPath<NUM_DP)
  2239.     {
  2240.         match=0;
  2241.         for(i=0;i<NumPath;i++)
  2242.         {
  2243.             if(strcmpi(Path[i],str)==0)
  2244.                 match=1;
  2245.         }
  2246.         if(match==0)
  2247.         {
  2248.             strcpy(Path[NumPath],str);
  2249.             NumPath+=1;
  2250.             add+=1;
  2251.         }
  2252.     }
  2253.     return(add);
  2254. }
  2255.  
  2256. /**************************************************************************
  2257. **
  2258. **
  2259. **
  2260. ************************************************************************* */
  2261.  
  2262. char fsplit(instring,path,name,type)
  2263.  
  2264. char *instring,*path,*name,*type;
  2265.  
  2266. {
  2267.     int i,j,k;
  2268.     int dot=-1,last_slash=-1,len=strlen(instring),first_slash=-1;
  2269.     int num=0,colon=-1;
  2270.     int disk=0;
  2271.     char string[STR_LEN];
  2272.  
  2273.     strcpy(string,instring);
  2274.     path[0]='\0';
  2275.     name[0]='\0';
  2276.     type[0]='\0';
  2277.  
  2278.     for(i=0;i<len;i++)
  2279.     {
  2280.         if(string[i]==':')
  2281.             colon=i;
  2282.         else if(string[i]=='\\')
  2283.         {
  2284.             last_slash=i;
  2285.             if(first_slash<0)
  2286.                 first_slash=i;
  2287.         }    
  2288.         else if(string[i]=='.')
  2289.             dot=i;
  2290.     }
  2291.     if(dot<0&&first_slash>=0&&last_slash<len-1)  /* d:test */
  2292.     {
  2293.         string[len]='\\';
  2294.         last_slash=len;
  2295.         len+=1;
  2296.         string[len]='\0';
  2297.     }
  2298.     if(dot<0&&first_slash<0&&len>colon-1)
  2299.     {
  2300.         string[len]='.';
  2301.         dot=len;
  2302.         len+=1;
  2303.         string[len]='\0';
  2304.     }
  2305.     if(colon>0)
  2306.         disk=string[0];
  2307.     if(first_slash>=0)
  2308.     {
  2309.         for(i=first_slash;i<=last_slash;i++)
  2310.             path[i-first_slash]=string[i];
  2311.         path[last_slash-first_slash+1]='\0';
  2312.     }
  2313.     if(last_slash>0&&last_slash<len-1&&dot>0)
  2314.     {
  2315.         for(i=last_slash+1;i<dot;i++)
  2316.             name[i-last_slash-1]=string[i];
  2317.         name[dot-last_slash-1]='\0';
  2318.     }
  2319.     if(colon>0&&last_slash<0&&dot>0)    /* d:test.img */
  2320.     {
  2321.         for(i=colon+1;i<dot;i++)
  2322.             name[i-colon-1]=string[i];
  2323.         name[dot-colon]='\0';
  2324.     }
  2325.     if(colon<0&&last_slash<0&&dot>0)    /* test.img */
  2326.     {
  2327.         for(i=0;i<dot;i++)
  2328.             name[i]=string[i];
  2329.         name[dot]='\0';
  2330.     }
  2331.     if(dot>0&&dot<len-1)
  2332.     {
  2333.         for(i=dot+1;i<len;i++)
  2334.             type[i-dot-1]=string[i];
  2335.         type[len-dot-1]='\0';
  2336.         if(strlen(type)>3)
  2337.             type[3]='\0';
  2338.     }
  2339.     return(disk);
  2340. }
  2341.  
  2342.  
  2343. /**************************************************************************
  2344. **
  2345. **
  2346. **
  2347. ************************************************************************* */
  2348.  
  2349. int annotate(ix,iy,size,color)
  2350.  
  2351. int *ix,*iy,*size,*color;
  2352.  
  2353. {
  2354.     int i,j,k;
  2355.     char string[STR_LEN],ans,ans2;
  2356.     int xc=*ix,yc=*iy,xs=ScreenXs-(*ix),ys=28/(*size),speed=16;
  2357.     int cxc=0,cyc=ScreenYs-28/(*size),cxs=ScreenXs,cys=28/(*size);
  2358.     int background=0;
  2359.  
  2360.     if(*color==0)
  2361.         background=M.Back;
  2362.     save_box(0,background,Mbuff,cxc,cyc,cxs,cys);
  2363.     i=0;
  2364.     string[0]='\0';
  2365.     do
  2366.     {
  2367.         ans=getch();
  2368.         if(ans==8&&i>0)
  2369.         {
  2370.             i-=1;
  2371.             string[i]='\0';
  2372.             unsave_box(0,background,Mbuff,cxc,cyc,cxs,cys);
  2373.             save_box(0,background,Mbuff,cxc,cyc,cxs,cys);
  2374.             plot_font_h(*color,cxc,cyc,string,*size,Font);
  2375.         }
  2376.         if(ans>=0x20)
  2377.         {
  2378.             string[i]=ans;
  2379.             string[i+1]='\0';
  2380.             plot_font_h(*color,cxc,cyc,string,*size,Font);
  2381.             i+=1;
  2382.         }
  2383.         if(ans==0)
  2384.         {
  2385.             ans2=getch();
  2386.             if(ans2>=71&&ans2<=73)
  2387.                 *color+=1;
  2388.             if(ans2>=79&&ans2<=81)
  2389.                 *color-=1;
  2390.             if(*color>15)
  2391.                 *color=0;
  2392.             if(*color<0)
  2393.                 *color=15;
  2394.             if(*color==0)
  2395.                 background=M.Back;
  2396.             else
  2397.                 background=0;
  2398.             unsave_box(0,background,Mbuff,cxc,cyc,cxs,cys);
  2399.             if(ans2==75&&*size<4)
  2400.                 *size+=1;
  2401.             if(ans2==77&&*size>1)
  2402.                 *size-=1;
  2403.             cyc=ScreenYs-28/(*size);
  2404.             ys=cys=28/(*size);
  2405.             save_box(0,background,Mbuff,cxc,cyc,cxs,cys);
  2406.             plot_font_h(*color,cxc,cyc,string,*size,Font);
  2407.         }
  2408.     }while(ans!=27&&ans!=13);
  2409.     unsave_box(0,background,Mbuff,cxc,cyc,cxs,cys);
  2410.     if(ans==27)
  2411.         return(ans);
  2412.     xs=strlen(string)*15/(*size);
  2413.     if(limit_area(&xc,&yc,&xs,&ys,&speed,ScreenXs,0,Mbuff)!=27&&
  2414.             strlen(string)>0)
  2415.         plot_font_h(*color,xc,yc,string,*size,Font);
  2416.     *ix=xc;
  2417.     *iy=yc;
  2418.     return(ans);
  2419. }
  2420.  
  2421. /**************************************************************************
  2422. **
  2423. **
  2424. **
  2425. ************************************************************************* */
  2426.  
  2427. int draw_line(ix,iy,color)
  2428.  
  2429. int *ix,*iy,*color;
  2430.  
  2431. {
  2432.     int i,j,k;
  2433.     char string[STR_LEN],ans,ans2;
  2434.     int x1=*ix,x2,y1=*iy,y2,speed=16,xo=*ix,yo=*iy;
  2435.     int val;
  2436.  
  2437.     val=getpt(0,x1,y1);
  2438.     tcursor(3,x1,y1,7,Mbuff);
  2439.     cursor(0,x1,y1,M.Comp_Color[val],7);
  2440.     do
  2441.     {
  2442.         ans=getch();
  2443.         if(ans==0)
  2444.         {
  2445.             ans2=getch();
  2446.             if(ans2==71)
  2447.             {
  2448.                 x1-=speed;
  2449.                 y1-=speed;
  2450.             }
  2451.             if(ans2==73)
  2452.             {
  2453.                 x1+=speed;
  2454.                 y1-=speed;
  2455.             }
  2456.             if(ans2==79)
  2457.             {
  2458.                 x1-=speed;
  2459.                 y1+=speed;
  2460.             }
  2461.             if(ans2==81)
  2462.             {
  2463.                 x1+=speed;
  2464.                 y1+=speed;
  2465.             }
  2466.             if(ans2==72)
  2467.                 y1-=speed;
  2468.             if(ans2==80)
  2469.                 y1+=speed;
  2470.             if(ans2==75)
  2471.                 x1-=speed;
  2472.             if(ans2==77)
  2473.                 x1+=speed;
  2474.             if(x1<0)
  2475.                 x1=0;
  2476.             if(x1>=ScreenXs)
  2477.                 x1=ScreenXs-1;
  2478.             if(y1<0)
  2479.                 y1=0;
  2480.             if(y1>=ScreenYs)
  2481.                 y1=ScreenYs-1;
  2482.         }
  2483.         if(ans=='-'&&speed>2)
  2484.             speed/=2;
  2485.         if(ans=='+'&&speed<128)
  2486.             speed*=2;
  2487.         uncursor(3,xo,yo,7,Mbuff);
  2488.         val=getpt(0,x1,y1);
  2489.         tcursor(3,x1,y1,7,Mbuff);
  2490.         cursor(0,x1,y1,M.Comp_Color[val],7);
  2491.         xo=x1;
  2492.         yo=y1;
  2493.     }while(ans!=27&&ans!=13);
  2494.     uncursor(3,xo,yo,7,Mbuff);
  2495.     if(ans==27)
  2496.         return(ans);
  2497.     xo=x2=x1;yo=y2=y1;
  2498.     tplotln_inv_dot(0,x1,y1,x2,y2,Mbuff,ScreenXs);
  2499.     tcursor(3,x2,y2,7,Buffer);
  2500.     cursor(0,x2,y2,*color,7);
  2501.     do
  2502.     {
  2503.         ans=getch();
  2504.         if(ans==0)
  2505.         {
  2506.             ans2=getch();
  2507.             if(ans2==71)
  2508.             {
  2509.                 x2-=speed;
  2510.                 y2-=speed;
  2511.             }
  2512.             if(ans2==73)
  2513.             {
  2514.                 x2+=speed;
  2515.                 y2-=speed;
  2516.             }
  2517.             if(ans2==79)
  2518.             {
  2519.                 x2-=speed;
  2520.                 y2+=speed;
  2521.             }
  2522.             if(ans2==81)
  2523.             {
  2524.                 x2+=speed;
  2525.                 y2+=speed;
  2526.             }
  2527.             if(ans2==72)
  2528.                 y2-=speed;
  2529.             if(ans2==80)
  2530.                 y2+=speed;
  2531.             if(ans2==75)
  2532.                 x2-=speed;
  2533.             if(ans2==77)
  2534.                 x2+=speed;
  2535.             if(x2<0)
  2536.                 x2=0;
  2537.             if(x2>=ScreenXs)
  2538.                 x2=ScreenXs-1;
  2539.             if(y2<0)
  2540.                 y2=0;
  2541.             if(y2>=ScreenYs)
  2542.                 y2=ScreenYs-1;
  2543.         }
  2544.         if(ans=='c')
  2545.             *color-=1;
  2546.         if(ans=='C')
  2547.             *color+=1;
  2548.         if(*color>15)
  2549.             *color=0;
  2550.         if(*color<0)
  2551.             *color=15;
  2552.         if(ans=='-'&&speed>2)
  2553.             speed/=2;
  2554.         if(ans=='+'&&speed<128)
  2555.             speed*=2;
  2556.         uncursor(0,xo,yo,7,Buffer);
  2557.         unplotln(0,x1,y1,xo,yo,Mbuff);
  2558.         xo=x2;
  2559.         yo=y2;
  2560.         tplotln_inv_dot(0,x1,y1,x2,y2,Mbuff,ScreenXs);
  2561.         plotln(0,x1,y1,x2,y2,*color);
  2562.         tcursor(0,x2,y2,7,Buffer);
  2563.         cursor(0,x2,y2,*color,7);
  2564.     }while(ans!=27&&ans!=13);
  2565.     uncursor(3,xo,yo,7,Buffer);
  2566.     unplotln(0,x1,y1,xo,yo,Mbuff);
  2567.     if(ans==27)
  2568.         return(ans);
  2569.     plotln(0,x1,y1,x2,y2,*color);
  2570.     *ix=x2;
  2571.     *iy=y2;
  2572.     return(ans);
  2573. }
  2574.  
  2575.  
  2576. /**************************************************************************
  2577. **
  2578. **
  2579. **
  2580. ************************************************************************* */
  2581.  
  2582. int vector_plot(pixsize)
  2583.  
  2584. float pixsize;
  2585.  
  2586. {
  2587.     int i,j,k;
  2588.     int v_num=0,val;
  2589.  
  2590.     for(i=0;i<M.Num_Type;i++)
  2591.         Menu_V[i]=M.Group_Name[i];
  2592.     Menu_V[M.Num_Type]=Exit;
  2593.     v_num=M_do_menu(Menu_V,M.Num_Type+1,MENUXC,25,v_num,
  2594.                             M.Mback,M.Text,M.High,Font);
  2595.     i=v_num;
  2596.     if(i>=0&&i<M.Num_Type)
  2597.     {
  2598.         for(j=0;j<M.Ns[i];j++)
  2599.         {
  2600.             if(M.MapFile[i][j].max_pix*PixScale>pixsize
  2601.                 &&M.MapFile[i][j].min_pix*PixScale<=pixsize)
  2602.             {
  2603.                 if(kbhit()>0)
  2604.                 {
  2605.                     val=getch();
  2606.                     if(val==27)
  2607.                         return(-2);
  2608.                 }
  2609.                 convert_bin(M.MapFile[i][j].color,
  2610.                     M.MapFile[i][j].filename);
  2611.             }
  2612.         }
  2613.     }
  2614.     return(0);
  2615. }
  2616.  
  2617.  
  2618. /**************************************************************************
  2619. **
  2620. **
  2621. **
  2622. ************************************************************************* */
  2623.  
  2624. int point_plot(pixsize,start)
  2625.  
  2626. float pixsize;
  2627. int start;
  2628.  
  2629. {
  2630.     int i,j,k;
  2631.     int p_num=start,p_numo=start,val;
  2632.  
  2633.     for(i=0;i<M.NumSymbol;i++)
  2634.         Menu_P[i]=PlaceFile[i].name;
  2635.     Menu_P[M.NumSymbol]="Plot All";
  2636.     Menu_P[M.NumSymbol+1]="All OFF";
  2637.     Menu_P[M.NumSymbol+2]="exit";
  2638.     do
  2639.     {
  2640.         p_num=M_do_menu(Menu_P,M.NumSymbol+3,MENUXC,25,p_num,
  2641.                                 M.Mback,M.Text,M.High,Font);
  2642.         i=p_num;
  2643.         if(i>=0&&i<M.NumSymbol)
  2644.         {
  2645.             p_numo=p_num;
  2646.             PlaceFile[i].on=1;
  2647.             if(PlaceFile[i].on==1&&
  2648.                     pixsize>=PlaceFile[i].min_pix&&pixsize<PlaceFile[i].max_pix)
  2649.                 symbol_plot(i,0);
  2650.         }
  2651.         if(p_num==M.NumSymbol)
  2652.         {
  2653.             for(i=0;i<M.NumSymbol;i++)
  2654.             {
  2655.                 p_numo=0;
  2656.                 PlaceFile[i].on=1;
  2657.                 if(PlaceFile[i].on==1&&
  2658.                     pixsize>=PlaceFile[i].min_pix&&pixsize<PlaceFile[i].max_pix)
  2659.                 symbol_plot(i,0);
  2660.             }
  2661.         }
  2662.         if(p_num==M.NumSymbol+1)
  2663.         {
  2664.             for(i=0;i<M.NumSymbol;i++)
  2665.             {
  2666.                 p_numo=0;
  2667.                 PlaceFile[i].on=0;
  2668.             }
  2669.         }
  2670.     }while(p_num<M.NumSymbol);
  2671.     return(p_numo);
  2672. }
  2673.  
  2674.  
  2675. /**************************************************************************
  2676. **
  2677. **
  2678. **
  2679. ************************************************************************* */
  2680.  
  2681. int search_list(list,string)
  2682.  
  2683. char *list,*string;
  2684.  
  2685. {
  2686.     int i,j,k;
  2687.     int p=-1;
  2688.     int val,kbval;
  2689.  
  2690.     for(j=0;j<NumPath;j++)
  2691.     {
  2692.         if(kbhit()>0)
  2693.         {
  2694.             kbval=getch();
  2695.             if(kbval==27)
  2696.                 return(-2);
  2697.         }
  2698.         sprintf(String,"%s%s",Path[j],list);
  2699.         if(load_names(String)>0)
  2700.             val=get_file_name(String,string);
  2701.         else
  2702.             val=-1;
  2703.         if(val>=0)
  2704.             return(val);
  2705.     }
  2706.     return(val);
  2707. }
  2708.  
  2709.  
  2710. /**************************************************************************
  2711. **
  2712. **
  2713. **
  2714. ************************************************************************* */
  2715.  
  2716. int save_map(name)
  2717.  
  2718. char *name;
  2719.  
  2720. {
  2721.     int i,j,k;
  2722.     FILE *fp;
  2723.     double lat,lon;
  2724.  
  2725.     ScreenXs=MaxXs;
  2726.     ScreenYs=MaxYs;
  2727.     xy_ll((double)(ScreenXs/2),(double)(ScreenYs/2),&lat,&lon);
  2728.     miv.indat[0]=M.Pixsize;
  2729.     miv.indat[1]=M.Clat=lat;
  2730.     miv.indat[2]=M.Clon=lon;
  2731.     miv.indat[3]=M.Clon;
  2732.     miv.indat[4]=M.Clat+10;
  2733.     miv.indat[5]=M.Clat-10;
  2734.     map_pos.xc=0;    
  2735.     map_pos.yc=0;
  2736.     map_pos.xs=ScreenXs;
  2737.     map_pos.ys=ScreenYs;
  2738.     auto_set_cc(miv.type,miv.indat);
  2739.     fp=open_to_write_binary(name);
  2740.     if(!fp)
  2741.         return(-1);
  2742.     strcpy(LastMap,LastFile);
  2743. /*    setbuf(fp,Inbuff);*/
  2744.     M.screen_xs=ScreenXs;
  2745.     M.screen_ys=ScreenYs;
  2746.     fwrite((char *)&M,sizeof(struct map),1,fp);
  2747.     if(M.NumSymbol>0)
  2748.         fwrite((char *)PlaceFile,sizeof(struct symbol_name),M.NumSymbol,fp);
  2749.     for(i=0;i<MaxYs;i++)
  2750.     {
  2751.         getrow(0,0,MaxXs-1,i,Buffer);
  2752.         fwrite((char *)Buffer,sizeof(char),MaxXs,fp);
  2753.     }
  2754.     fclose(fp);
  2755.     return(1);
  2756. }
  2757. /**************************************************************************
  2758. **
  2759. **
  2760. **
  2761. ************************************************************************* */
  2762.  
  2763. int unsave_map(name)
  2764.  
  2765. char *name;
  2766.  
  2767. {
  2768.     int i,j,k;
  2769.     FILE *fp;
  2770.  
  2771.     ScreenXs=MaxXs;
  2772.     ScreenYs=MaxYs;
  2773.     fp=open_to_read_binary(name);
  2774.     if(fp==NULL)
  2775.         return(-1);
  2776.     strcpy(LastMap,LastFile);
  2777. /*    setbuf(fp,Inbuff);*/
  2778.     fread((char *)&M,sizeof(struct map),1,fp);
  2779.     if(M.NumSymbol>0)
  2780.         fread((char *)PlaceFile,sizeof(struct symbol_name),M.NumSymbol,fp);
  2781.     ScreenXs=M.screen_xs;
  2782.     ScreenYs=M.screen_ys;
  2783.     WritePalette(M.lut); 
  2784.     for(i=0;i<MaxYs;i++)
  2785.     {
  2786.         fread((char *)Buffer,sizeof(char),MaxXs,fp);
  2787.         plotrow(0,0,MaxXs-1,i,Buffer);
  2788.     }
  2789.     fclose(fp);
  2790.     miv.indat[0]=M.Pixsize;
  2791.     miv.indat[1]=M.Clat;
  2792.     miv.indat[2]=M.Clon;
  2793.     miv.indat[3]=M.Clon;
  2794.     miv.indat[4]=M.Clat+10;
  2795.     miv.indat[5]=M.Clat-10;
  2796.     miv.type=M.Type;
  2797.     map_pos.xc=0;    
  2798.     map_pos.yc=0;
  2799.     map_pos.xs=ScreenXs;
  2800.     map_pos.ys=ScreenYs;
  2801.     auto_set_cc(miv.type,miv.indat);
  2802.     screen_mm();
  2803.     if(M.Num_Type>NUM_TYPE)
  2804.     {
  2805.         SetVideoMode(0);
  2806.         printf("Too many vector groups.\n");
  2807.         exit(0);
  2808.     }
  2809.     for(i=0;i<M.Num_Type;i++)
  2810.     {
  2811.         strcpy(T_Menu_L[i][0],M.Group_Name[i]);
  2812.         strcat(T_Menu_L[i][0]," OFF");
  2813.         strcpy(T_Menu_L[i][1],M.Group_Name[i]);
  2814.         strcat(T_Menu_L[i][1]," ON");
  2815.     }
  2816.     i=M.Num_Type;
  2817.     strcpy(T_Menu_L[i+0][0],"all ON");
  2818.     strcpy(T_Menu_L[i+0][1],"all ON");
  2819.     strcpy(T_Menu_L[i+1][0],"all OFF");
  2820.     strcpy(T_Menu_L[i+1][1],"all OFF");
  2821.     strcpy(T_Menu_L[i+2][0],"exit");
  2822.     strcpy(T_Menu_L[i+2][1],"exit");
  2823.     return(1);
  2824. }
  2825.  
  2826. /**************************************************************************
  2827. **
  2828. **
  2829. **
  2830. ************************************************************************* */
  2831.  
  2832. int video_on()
  2833.  
  2834. {
  2835.     int i,row;
  2836.  
  2837.     i=GetVideoBoardID();
  2838. #ifdef NUMBER9
  2839.     VideoType='X';
  2840.     B_Id.row=1024;
  2841.     B_Id.col=1024;
  2842.     ScreenXs=1024;
  2843.     ScreenYs=1024;
  2844.     strcpy(Suffix,".nmp");
  2845.     FontSize=1;
  2846. #else
  2847.     if(VideoType=='X')
  2848.     {
  2849.         row=SetVideoMode(480,&B_Id);
  2850.         if(B_Id.row<400)
  2851.             VideoType='V';
  2852.         else
  2853.         {
  2854.             ScreenXs=640;
  2855.             ScreenYs=row;
  2856.         }
  2857.         if(B_Id.row==480)
  2858.             strcpy(Suffix,".xmp");
  2859.         else
  2860.             strcpy(Suffix,".ymp");
  2861.     }
  2862.     if(VideoType=='Y')
  2863.     {
  2864.         row=SetVideoMode(400,&B_Id);
  2865.         if(B_Id.row<400)
  2866.             VideoType='V';
  2867.         else
  2868.         {
  2869.             ScreenXs=640;
  2870.             ScreenYs=row;
  2871.         }
  2872.         strcpy(Suffix,".ymp");
  2873.     }
  2874.     if(VideoType=='V')
  2875.     {
  2876.         row=SetVideoMode(0x12,&B_Id);
  2877.         if(B_Id.row!=480)
  2878.             VideoType='E';
  2879.         else
  2880.         {
  2881.             ScreenXs=640;
  2882.             ScreenYs=480;
  2883.             Num_Color=M.Num_Color=16;
  2884.             strcpy(Suffix,".vmp");
  2885.         }
  2886.     }
  2887.     if(VideoType=='S')
  2888.     {
  2889.         row=SetVideoMode(0x13,&B_Id);
  2890.         if(B_Id.row!=200)
  2891.         {
  2892.             SetVideoMode(0,&B_Id);
  2893.             printf("Could not boot color board.\n");
  2894.             exit(0);
  2895.         }
  2896.         ScreenXs=320;
  2897.         ScreenYs=200;
  2898.         Num_Color=M.Num_Color=256;
  2899.         strcpy(Suffix,".smp");
  2900.         FontSize=3;
  2901.     }
  2902.     if(VideoType=='E')
  2903.     {
  2904.         row=SetVideoMode(0x10,&B_Id);
  2905.         if(B_Id.row!=350)
  2906.         {
  2907.             SetVideoMode(0,&B_Id);
  2908.             printf("Could not boot color board.\n");
  2909.             exit(0);
  2910.         }
  2911.         ScreenXs=640;
  2912.         ScreenYs=350;
  2913.         Num_Color=M.Num_Color=16;
  2914.         strcpy(Suffix,".emp");
  2915.     }
  2916.     if(B_Id.row<0)
  2917.     {
  2918.         SetVideoMode(0,&B_Id);
  2919.         printf("Could not boot board -- row = %d\n\n",row);
  2920.         exit(0);
  2921.     }
  2922. #endif
  2923.     MaxXs=ScreenXs=B_Id.col;
  2924.     MaxYs=ScreenYs=B_Id.row;
  2925.     PixScale=480.0;
  2926.     PixScale/=(float)ScreenYs;
  2927.     strcpy(SubType,Suffix);
  2928.     SubType[3]='g';
  2929. }
  2930.  
  2931.  
  2932.  
  2933. /********************************************************************
  2934. **
  2935. **    WARNING!!!!  YOU MUST CALL decode_font() or set_files() before using
  2936. **
  2937. **     options:
  2938. **
  2939. **       -1 -- remove menu but get no answer
  2940. **        0 -- return answer and set menu colors to greys
  2941. **        1 -- return answer but leave colors alone
  2942. **
  2943. ********************************************************************* */
  2944.  
  2945. int M_do_menu(menu,num,xc,yc,start,back,words,boxs,font)
  2946.  
  2947. char *menu[];
  2948. int num,xc,yc,start,back,words,boxs;
  2949. int font[128][25];
  2950.  
  2951. {
  2952.     int i,j,k;
  2953.     char ans,ans2;
  2954.     int len=0,l,size=FontSize,val,valo;
  2955.     int black=0,dgrey=back,lgrey=words,white=boxs;
  2956.     int wide;
  2957.     long lxs,lys,buffersize=(long)B_LINES*(long)MAX_X;
  2958.  
  2959.     for(k=0;k<num;k++)
  2960.         if((l=strlen(menu[k]))>len)len=l;
  2961.     if(len==0)return(-1);
  2962.     do
  2963.     {
  2964.         wide=(len+1)*15/size+1;
  2965.         if((ScreenXs-1-wide)<xc)xc=ScreenXs-1-wide;
  2966.         lxs=(len+1)*15/size+1;
  2967.         lys=30/size*num+1;
  2968.         if(lxs*lys>buffersize)
  2969.             size+=1;
  2970.         if(size>4)
  2971.         {
  2972.             SetVideoMode(0);            
  2973.             printf("Could not fit menu into buffer for 'save_box()'\n");
  2974.             exit(0);
  2975.         }
  2976.     }while(lxs*lys>buffersize);
  2977.     if((xc+(len+1)*15/size+1)<ScreenXs)
  2978.     {
  2979.         save_box(0,dgrey,Mbuff,
  2980.             xc,yc,(len+1)*15/size+1,30/size*num+1);
  2981.         for(k=0;k<num;k++)
  2982.         {    
  2983.             box(0,xc,yc+k*(30/size),dgrey,(len+1)*15/size,30/size);
  2984.             plot_font_h(lgrey,
  2985.                     xc+15/size,yc+k*30/size+5/size,menu[k],size,font);
  2986.         }
  2987.         box(0,xc,yc,lgrey,(len+1)*15/size,30/size*num);
  2988.  
  2989.         val=valo=start;
  2990.         box(0,xc,yc+val*(30/size),white,(len+1)*15/size,30/size);
  2991.         do
  2992.         {
  2993.             if((ans=getch())==0)
  2994.             {
  2995.                 ans2=getch();
  2996.                 if(ans2==50)
  2997.                 {
  2998.                     unsave_box(0,dgrey,Mbuff,
  2999.                         xc,yc,(len+1)*15/size+1,30/size*num+1);
  3000.                     getch();
  3001.                     paint_box(0,dgrey,MT_Buff,
  3002.                         xc,yc,(len+1)*15/size+1,30/size*num+1);
  3003.                     for(k=0;k<num;k++)
  3004.                     {    
  3005.                         plot_font_h(lgrey,
  3006.                     xc+15/size,
  3007.                                     yc+k*30/size+5/size,menu[k],size,font);
  3008.                     }
  3009.                 }
  3010.                 if(ans2=='H')
  3011.                 {
  3012.                     if(val>0)val-=1;
  3013.                     else val=num-1;
  3014.                 }
  3015.                 if(ans2=='P')
  3016.                 {
  3017.                     if(val<num-1)val+=1;
  3018.                     else val=0;
  3019.                 }
  3020.             }
  3021.  
  3022.             for(i=0;i<num;i++)
  3023.                 if(ans==menu[i][0])
  3024.                 {
  3025.                     val=i;
  3026.                     ans=13;
  3027.                 }
  3028.  
  3029.             box(0,xc,yc+valo*(30/size),dgrey,(len+1)*15/size,30/size);
  3030.             valo=val;
  3031.             box(0,xc,yc,lgrey,(len+1)*15/size,30/size*num);
  3032.             box(0,xc,yc+val*(30/size),white,(len+1)*15/size,30/size);
  3033.             if(ans==27)
  3034.             {
  3035.                 val=num-1;
  3036.                 ans=13;
  3037.             }
  3038.         }while(ans!=13);
  3039.     }
  3040.     box(0,xc,yc,dgrey,(len+1)*15/size,30/size*num);
  3041.     box(0,xc,yc+val*(30/size),lgrey,(len+1)*15/size,30/size);
  3042.     unsave_box(0,dgrey,Mbuff,
  3043.             xc,yc,(len+1)*15/size+1,30/size*num+1);
  3044.     return(val);
  3045. }
  3046.  
  3047.  
  3048.  
  3049. /********************************************************************
  3050. **
  3051. **    WARNING!!!!  YOU MUST CALL decode_font() or set_files() before using
  3052. **
  3053. **     options:
  3054. **
  3055. **       -1 -- remove menu but get no answer
  3056. **        0 -- return answer and set menu colors to greys
  3057. **        1 -- return answer but leave colors alone
  3058. **
  3059. ********************************************************************* */
  3060.  
  3061. int T_do_menu(menu,num,xc,yc,start,back,words,boxs,font,off_on)
  3062.  
  3063. char menu[][2][50];
  3064. int num,xc,yc,start,back,words,boxs;
  3065. int font[128][25],*off_on;
  3066.  
  3067. {
  3068.     int i,j,k;
  3069.     char ans,ans2;
  3070.     int len=0,l,size=FontSize,val,valo;
  3071.     int black=0,dgrey=back,lgrey=words,white=boxs;
  3072.     int wide;
  3073.     long lxs,lys,buffersize=(long)B_LINES*(long)MAX_X;
  3074.  
  3075.     for(k=0;k<num;k++)
  3076.         if((l=strlen(menu[k][0]))>len)len=l;
  3077.     if(len==0)return(-1);
  3078.     do
  3079.     {
  3080.         wide=(len+1)*15/size+1;
  3081.         if((ScreenXs-1-wide)<xc)xc=ScreenXs-1-wide;
  3082.         lxs=(len+1)*15/size+1;
  3083.         lys=30/size*num+1;
  3084.         if(lxs*lys>buffersize)
  3085.             size+=1;
  3086.         if(size>4)
  3087.         {
  3088.             SetVideoMode(0);            
  3089.             printf("Could not fit menu into buffer for 'save_box()'\n");
  3090.             exit(0);
  3091.         }
  3092.     }while(lxs*lys>buffersize);
  3093.     if((ScreenXs-1-wide)<xc)xc=ScreenXs-1-wide;
  3094.     if((xc+(len+1)*15/size+1)<ScreenXs)
  3095.     {
  3096.         paint_box(0,dgrey,Mbuff,xc,yc,(len+1)*15/size+1,30/size*num+1);
  3097.         for(k=0;k<num-3;k++)
  3098.         {    
  3099.             box(0,xc,yc+k*(30/size),dgrey,(len+1)*15/size,30/size);
  3100.             plot_font_h(lgrey,xc+15/size,yc+k*30/size+5/size,menu[k][off_on[k]],
  3101.                 size,font);
  3102.         }
  3103.         for(k=num-3;k<num;k++)
  3104.         {    
  3105.             box(0,xc,yc+k*(30/size),dgrey,(len+1)*15/size,30/size);
  3106.             plot_font_h(lgrey,xc+15/size,yc+k*30/size+5/size,menu[k][0],
  3107.                 size,font);
  3108.         }
  3109.         box(0,xc,yc,lgrey,(len+1)*15/size,30/size*num);
  3110.  
  3111.         val=valo=start;
  3112.         box(0,xc,yc+val*(30/size),white,(len+1)*15/size,30/size);
  3113.         do
  3114.         {
  3115.             ans=getch();
  3116.             if(ans==13)
  3117.             {
  3118.                 if(val<num-3)
  3119.                 {
  3120.                     if(off_on[val]==0)
  3121.                         off_on[val]=1;
  3122.                     else
  3123.                         off_on[val]=0;
  3124.                 }
  3125.                 if(val==num-3)
  3126.                     for(k=0;k<num-3;k++)
  3127.                         off_on[k]=1;
  3128.                 if(val==num-2)
  3129.                     for(k=0;k<num-3;k++)
  3130.                         off_on[k]=0;
  3131.                 paint_box(0,dgrey,Mbuff,xc,yc,
  3132.                     (len+1)*15/size+1,30/size*num+1);
  3133.                 for(k=0;k<num-3;k++)
  3134.                 {    
  3135.                     box(0,xc,yc+k*(30/size),dgrey,(len+1)*15/size,30/size);
  3136.                     plot_font_h(lgrey,xc+15/size,yc+k*30/size+5/size,
  3137.                             menu[k][off_on[k]],size,font);
  3138.                 }
  3139.                 for(k=num-3;k<num;k++)
  3140.                 {    
  3141.                     box(0,xc,yc+k*(30/size),dgrey,(len+1)*15/size,30/size);
  3142.                     plot_font_h(lgrey,xc+15/size,yc+k*30/size+5/size,
  3143.                             menu[k][0],size,font);
  3144.                 }
  3145.                 box(0,xc,yc,lgrey,(len+1)*15/size,30/size*num);
  3146.             }
  3147.             if(ans==13&&val==num-1)
  3148.                 ans=27;
  3149.             if(ans==0)
  3150.             {
  3151.                 ans2=getch();
  3152.                 if(ans2=='H')
  3153.                 {
  3154.                     if(val>0)val-=1;
  3155.                     else val=num-1;
  3156.                 }
  3157.                 if(ans2=='P')
  3158.                 {
  3159.                     if(val<num-1)val+=1;
  3160.                     else val=0;
  3161.                 }
  3162.             }
  3163.             for(i=0;i<num;i++)
  3164.                 if(ans==menu[i][0][0])
  3165.                 {
  3166.                     val=i;
  3167.                     ans=27;
  3168.                 }
  3169.             box(0,xc,yc+valo*(30/size),dgrey,(len+1)*15/size,30/size);
  3170.             valo=val;
  3171.             box(0,xc,yc,lgrey,(len+1)*15/size,30/size*num);
  3172.             box(0,xc,yc+val*(30/size),white,(len+1)*15/size,30/size);
  3173.         }while(ans!=27);
  3174.     }
  3175.     box(0,xc,yc,dgrey,(len+1)*15/size,30/size*num);
  3176.     box(0,xc,yc+val*(30/size),lgrey,(len+1)*15/size,30/size);
  3177.  
  3178.     return(val);
  3179. }
  3180.  
  3181.  
  3182.  
  3183. /**************************************************************************
  3184. **
  3185. **
  3186. **
  3187. ************************************************************************* */
  3188.  
  3189. int read_control(filename)
  3190.  
  3191. char *filename;
  3192.  
  3193. {
  3194.     int i,j,k,n=1,m,p=0,u,v;
  3195.     FILE *fp;
  3196.     char string1[100],string2[100],string2a[100],string3[100],string2b[100];
  3197.     char nam[100],type;
  3198.     int numread,val,numcolors;
  3199.  
  3200.     fp=open_to_read_binary(filename);
  3201.     if(!fp)
  3202.         return(-1);
  3203.     fscanf(fp,"%s",string1);
  3204.     if(strlen(string1)==1)
  3205.     {
  3206.         type=string1[0];
  3207.         if(type=='l'||type=='a'||type=='m'||
  3208.             type=='s'||type=='p'||type=='S')
  3209.         {
  3210.             M.Type=type;
  3211.             numread=fscanf(fp,"%f%f%f%f",&M.Pixsize,&M.Clat,&M.Clon,&M.Space);
  3212.             if(numread!=4)
  3213.             {
  3214.                 return(-6);
  3215.             }
  3216.         }
  3217.     }
  3218.  
  3219.     do
  3220.     {
  3221.         numread=fscanf(fp,"%s",string1);
  3222.     }while(numread>0&&strcmpi(string1,"begin_color")!=0);
  3223.     if(numread<1)
  3224.         return(-2);        /* could not find 'begin_color' */
  3225.  
  3226.     i=0;
  3227.     do
  3228.     {
  3229.         fscanf(fp,"%s",M.Color_Name[i]);
  3230.         if(strcmpi(M.Color_Name[i],"end_color")!=0)
  3231.         {
  3232.             numread=fscanf(fp,"%s%d%d%d",
  3233.                 string1,&M.Color_Val[i][0],&M.Color_Val[i][1],&M.Color_Val[i][2]);
  3234.             if(strcmpi(M.Color_Name[i],"white")==0)
  3235.             {
  3236.                 M.White=i;
  3237.             }
  3238.             if(strcmpi(M.Color_Name[i],"black")==0)
  3239.             {
  3240.                 M.Black=i;
  3241.             }
  3242.         }
  3243.         if(numread==4&&M.Out==1&&Fpout)
  3244.             fprintf(Fpout,"%20s = %4d%4d%4d\n",M.Color_Name[i],
  3245.                 M.Color_Val[i][0],M.Color_Val[i][1],M.Color_Val[i][2]);
  3246.         i+=1;
  3247.     }while(numread==4&&strcmpi(M.Color_Name[i-1],"end_color")!=0&&i<MAX_COLORS);
  3248.     numcolors=i;
  3249.     do
  3250.     {
  3251.         numread=fscanf(fp,"%s",string1);
  3252.         if(strcmpi(string1,"menu_background")==0)
  3253.         {
  3254.             fscanf(fp,"%s%s",string2,string3);
  3255.             if(M.Out==1&&Fpout)
  3256.                 fprintf(Fpout,"%16s = %s\n",string1,string3);
  3257.             val=get_color(string3);
  3258.             if(val>=0&&val<MAX_COLORS)
  3259.                 M.Mback=val;
  3260.             else
  3261.             {
  3262.                 printf("'%s' %s '%s'\n",string1,string2,string3);
  3263.                 return(-5);    /* bad color name */
  3264.             }
  3265.         }
  3266.         if(strcmpi(string1,"text")==0)
  3267.         {
  3268.             fscanf(fp,"%s%s",string2,string3);
  3269.             if(M.Out==1&&Fpout)
  3270.                 fprintf(Fpout,"%16s = %s\n",string1,string3);
  3271.             val=get_color(string3);
  3272.             if(val>=0&&val<MAX_COLORS)
  3273.                 M.Text=val;
  3274.             else
  3275.             {
  3276.                 printf("'%s' %s '%s'\n",string1,string2,string3);
  3277.                 return(-5);    /* bad color name */
  3278.             }
  3279.         }
  3280.         if(strcmpi(string1,"highlight")==0)
  3281.         {
  3282.             fscanf(fp,"%s%s",string2,string3);
  3283.             if(M.Out==1&&Fpout)
  3284.                 fprintf(Fpout,"%16s = %s\n",string1,string3);
  3285.             val=get_color(string3);
  3286.             if(val>=0&&val<MAX_COLORS)
  3287.                 M.High=val;
  3288.             else
  3289.             {
  3290.                 printf("'%s %s '%s'\n",string1,string2,string3);
  3291.                 return(-5);    /* bad color name */
  3292.             }
  3293.         }
  3294.         if(strcmpi(string1,"background")==0)
  3295.         {
  3296.             fscanf(fp,"%s%s",string2,string3);
  3297.             if(M.Out==1&&Fpout)
  3298.                 fprintf(Fpout,"%16s = %s\n",string1,string3);
  3299.             val=get_color(string3);
  3300.             if(val>=0&&val<MAX_COLORS)
  3301.                 M.Back=val;
  3302.             else
  3303.             {
  3304.                 printf("'%s' %s '%s'\n",string1,string2,string3);
  3305.                 return(-5);    /* bad color name */
  3306.             }
  3307.         }
  3308.         if(strcmpi(string1,"graticule")==0)
  3309.         {
  3310.             fscanf(fp,"%s%s",string2,string3);
  3311.             if(M.Out==1&&Fpout)
  3312.                 fprintf(Fpout,"%16s = %s\n",string1,string3);
  3313.             val=get_color(string3);
  3314.             if(val>=0&&val<MAX_COLORS)
  3315.                 M.Grat=val;
  3316.             else
  3317.             {
  3318.                 printf("'%s' %s '%s'\n",string1,string2,string3);
  3319.                 return(-5);    /* bad color name */
  3320.             }
  3321.         }
  3322.         if(strcmpi(string1,"lat/lon")==0)
  3323.         {
  3324.             fscanf(fp,"%s%s",string2,string3);
  3325.             if(M.Out==1&&Fpout)
  3326.                 fprintf(Fpout,"%16s = %s\n",string1,string3);
  3327.             val=get_color(string3);
  3328.             if(val>=0&&val<MAX_COLORS)
  3329.                 M.LatLon=val;
  3330.             else
  3331.             {
  3332.                 printf("'%s' %s '%s'\n",string1,string2,string3);
  3333.                 return(-5);    /* bad color name */
  3334.             }
  3335.         }
  3336.         if(strcmpi(string1,"black")==0)
  3337.         {
  3338.             fscanf(fp,"%s%s",string2,string3);
  3339.             if(M.Out==1&&Fpout)
  3340.                 fprintf(Fpout,"%16s = %s\n",string1,string3);
  3341.             val=get_color(string3);
  3342.             if(val>=0&&val<MAX_COLORS)
  3343.                 M.Black=val;
  3344.             else
  3345.             {
  3346.                 printf("'%s' %s '%s'\n",string1,string2,string3);
  3347.                 return(-5);    /* bad color name */
  3348.             }
  3349.         }
  3350.     }while(numread>0&&strcmpi(string1,"begin_vector")!=0);
  3351.     if(numread<1)
  3352.         return(-3);        /* could not find 'begin_vector' */
  3353.     i=0;
  3354.     do
  3355.     {
  3356.         numread=fscanf(fp,"%s",M.Group_Name[i]);
  3357.         if(numread==1&&strcmpi(M.Group_Name[i],"begin_names")==0)
  3358.         {
  3359.             do
  3360.             {
  3361.                 numread==fscanf(fp,"%s",String);
  3362.                 if(strcmpi(String,"end_names")!=0)
  3363.                 {
  3364.                     strcpy(PlaceFile[p].name,String);
  3365.                     fscanf(fp,"%s%s",string1,string2);
  3366.                     {
  3367.                         if(strcmpi(string2,"ON")==0)
  3368.                             PlaceFile[p].on=1;
  3369.                         else if(strcmpi(string2,"OFF")==0)
  3370.                             PlaceFile[p].on=0;
  3371.                         else
  3372.                         {
  3373.                             printf("'%s' is not marked ON or OFF\n\n",
  3374.                                 PlaceFile[p].name);
  3375.                             exit(0);
  3376.                         }
  3377.                     }
  3378.                     fscanf(fp,"%s%f%f%s",
  3379.                         PlaceFile[p].filename,
  3380.                         &PlaceFile[p].max_pix,&PlaceFile[p].min_pix,
  3381.                         string3);
  3382.                     val=get_color(string3);
  3383.                     if(val>=0&&val<MAX_COLORS)
  3384.                         PlaceFile[p].color=val;
  3385.                     else
  3386.                     {
  3387.                         printf("'%s' %s '%s'\n",string1,string2,string3);
  3388.                         return(-5);    /* bad color name */
  3389.                     }
  3390.                     for(u=0;u<SYM_SIZE;u++)
  3391.                     {
  3392.                         fscanf(fp,"%s",string1);
  3393.                         if(strlen(string1)!=SYM_SIZE)
  3394.                         {
  3395.                             printf("Bad symbol -- must be %d x %d\n",
  3396.                                 Sym_Size,Sym_Size);
  3397.                             printf("%s %s %f %f %d\n",
  3398.                                 PlaceFile[p].filename,
  3399.                                 PlaceFile[p].max_pix,
  3400.                                 PlaceFile[p].min_pix,
  3401.                                 PlaceFile[p].color);
  3402.                             return(-12);
  3403.                         }
  3404.                         for(v=0;v<SYM_SIZE;v++)
  3405.                             PlaceFile[p].Symbol[u][v]=string1[v];
  3406.                     }
  3407.                     p+=1;
  3408.                     if(p>=NUM_SYM)
  3409.                     {
  3410.                         printf("Too many symbols\n");
  3411.                         exit(0);
  3412.                     }
  3413.                     M.NumSymbol=p;
  3414.                 }
  3415.             }while(strcmpi(String,"end_names")!=0);
  3416.             numread=3;
  3417.         }
  3418.         else if(numread==1&&strcmpi(M.Group_Name[i],"fillin_ihs")==0)
  3419.         {
  3420.             M.Fill_In=3;
  3421.             M.Fill_After=i-1;
  3422.             fscanf(fp,"%s%d",String,&M.Num_Fill);
  3423.             for(m=0;m<M.Num_Fill;m++)
  3424.             {
  3425.                 fscanf(fp,"%s",M.Fill_In_Name[m]);
  3426.                 add_disk_path(M.Fill_In_Name[m]);
  3427.                 numread=fscanf(fp,"%f%f",&M.FI_max[m],&M.FI_min[m]);
  3428.                 if(numread<2)
  3429.                 {
  3430.                     printf("Bad max or min in fill group assignment '%s'\n",
  3431.                         M.Fill_In_Name[m]);
  3432.                     exit(0);
  3433.                 }
  3434.             }
  3435.             if(numread!=2)
  3436.             {
  3437.                 printf("Could not find max min pixel sizes for fill file\n");
  3438.                 exit(0);
  3439.             }
  3440.             do
  3441.             {
  3442.                 fscanf(fp,"%s",string1);
  3443.                 if(strcmpi(string1,"end")!=0)
  3444.                 {
  3445.                     numread=fscanf(fp,"%s%s%s%s",string2,string2a,string2b,string3);
  3446.                     if(numread<4)
  3447.                     {
  3448.                         printf("Error (1) reading fill color %d\n",k+1);
  3449.                         exit(0);
  3450.                     }
  3451.                     if(sscanf(string1,"%d",&k)<1)
  3452.                     {
  3453.                         printf("Error (2) reading fill color %d\n",k+1);
  3454.                         exit(0);
  3455.                     }
  3456.                     sscanf(string2,"%f",M.Fill_Color_IHS[k]);
  3457.                     sscanf(string2a,"%f",M.Fill_Color_IHS[k]+1);
  3458.                     sscanf(string2b,"%f",M.Fill_Color_IHS[k]+2);
  3459.                     if(k>M.Max_Fill)
  3460.                         M.Max_Fill=k;
  3461.                     M.Fill_Order[n++]=k;
  3462.                     strcpy(M.Fill_Name[k],string3);
  3463.                 }
  3464.             }while(strcmpi(string1,"end")!=0);
  3465.             numread=3;
  3466.         }
  3467.         else
  3468.         {
  3469.             if(numread==1&&strcmpi(M.Group_Name[i],"end_vector")!=0)
  3470.             {
  3471.                 numread=fscanf(fp,"%s%d%s",
  3472.                     string1,&M.Ns[i],string2);
  3473.                 strcpy(T_Menu_L[i][0],M.Group_Name[i]);
  3474.                 strcat(T_Menu_L[i][0]," OFF");
  3475.                 strcpy(T_Menu_L[i][1],M.Group_Name[i]);
  3476.                 strcat(T_Menu_L[i][1]," ON");
  3477.                 if(M.Out==1&&Fpout)
  3478.                     fprintf(Fpout,"\n%s = %d %s \n",M.Group_Name[i],M.Ns[i],string2);
  3479.                 if(strcmpi(string2,"ON")==0)
  3480.                     M.Mm[i]=1;
  3481.                 else
  3482.                     M.Mm[i]=0;
  3483.                 if(M.Ns[i]==0||M.Ns[i]>NUM_SIZE)
  3484.                 {
  3485.                     printf("Bad M.Ns = %d\n",M.Ns[i]);
  3486.                     return(-4);    /* too many vectors in a group */
  3487.                 }
  3488.             }
  3489.             for(k=0;k<M.Ns[i];k++)
  3490.             {
  3491.                 fscanf(fp,"%s%f%f%s",M.MapFile[i][k].filename,
  3492.                     &M.MapFile[i][k].max_pix,&M.MapFile[i][k].min_pix,
  3493.                     string1);
  3494.                 sprintf(nam,"%s.bin",M.MapFile[i][k].filename);
  3495.                 add_disk_path(nam);
  3496.                 val=get_color(string1);
  3497.                 if(val>=0&&val<MAX_COLORS)
  3498.                     M.MapFile[i][k].color=val;
  3499.                 else
  3500.                 {
  3501.                     printf("'%s' %f %f '%s'\n",
  3502.                         M.MapFile[i][k].filename,
  3503.                         M.MapFile[i][k].max_pix,M.MapFile[i][k].min_pix,
  3504.                         string1);
  3505.                     return(-5);    /* bad color name */
  3506.                 }
  3507.                 if(M.Out==1&&Fpout)
  3508.                     fprintf(Fpout,"%20s %8.4f %8.4f %10s = %2d\n",
  3509.                         M.MapFile[i][k].filename,
  3510.                         M.MapFile[i][k].max_pix,M.MapFile[i][k].min_pix,
  3511.                         string1,M.MapFile[i][k].color);
  3512.             }
  3513.             i+=1;
  3514.         }
  3515.     }while(numread==3&&strcmpi(M.Group_Name[i-1],"end_vector")!=0&&i<NUM_TYPE);
  3516.     i-=1;
  3517.     M.Num_Type=i;
  3518.     strcpy(T_Menu_L[i+0][0],"all ON");
  3519.     strcpy(T_Menu_L[i+0][1],"all ON");
  3520.     strcpy(T_Menu_L[i+1][0],"all OFF");
  3521.     strcpy(T_Menu_L[i+1][1],"all OFF");
  3522.     strcpy(T_Menu_L[i+2][0],"exit");
  3523.     strcpy(T_Menu_L[i+2][1],"exit");
  3524.     fclose(fp);
  3525.     return(1);
  3526. }
  3527.  
  3528.  
  3529.  
  3530. /**************************************************************************
  3531. **
  3532. **
  3533. **
  3534. ************************************************************************* */
  3535.  
  3536. int get_color(string)
  3537.  
  3538. char *string;
  3539.  
  3540. {
  3541.     int i,j,k;
  3542.     int val=-1;
  3543.  
  3544.     for(i=0;i<MAX_COLORS;i++)
  3545.         if(strcmpi(M.Color_Name[i],string)==0)
  3546.             return(i);
  3547.     return(-1);
  3548. }
  3549.  
  3550. /********************************************************************
  3551. **
  3552. **
  3553. **
  3554. ********************************************************************* */
  3555.  
  3556. char Zoom(xc,yc,xs,ys,pixsize,clat,clon,space)
  3557.  
  3558. int xc,yc,xs,ys;
  3559. float *pixsize,*clat,*clon,*space;
  3560.  
  3561. {
  3562.     int i,j,k,k1,k2;
  3563.     char ans,ans2;
  3564.     int ix[4],iy[4],speed=16;
  3565.     float m_ps=*pixsize,m_clon=*clon,m_clat=*clat,m_space=*space;
  3566.     float cur_ps=*pixsize/2.0,cur_clon=*clon,cur_clat=*clat,cur_space=*space;
  3567.     float cur_scale=1.189207115;
  3568.     int cur_ix=xc+xs/2,cur_iy=yc+ys/2;
  3569.     double dlat,dlon;
  3570.     int txs,screen_xs,lsize=FontSize;
  3571.  
  3572.     if(VideoType=='S')
  3573.         lsize=3;
  3574.     if(cur_ps<MIN_PIX)cur_ps=MIN_PIX;
  3575.  
  3576.     xy_ll((double)cur_ix,(double)cur_iy,&dlat,&dlon);
  3577.     cur_clat=dlat;cur_clon=dlon;
  3578.     get_corners(xc,yc,xs,ys,m_ps,m_clat,m_clon,cur_ps,cur_clat,cur_clon,ix,iy);
  3579.  
  3580.     tplotln_val(0,ix[0],iy[0]+1,ix[1],iy[1],MT_Buff[0],M.White);
  3581.     tplotln_val(0,ix[1]+1,iy[1],ix[2],iy[2],MT_Buff[1],M.White);
  3582.     tplotln_val(0,ix[2],iy[2]-1,ix[3],iy[3],MT_Buff[2],M.White);
  3583.     tplotln_val(0,ix[3]-1,iy[3],ix[0],iy[0],MT_Buff[3],M.White);
  3584.  
  3585.     do
  3586.     {
  3587.         ans=getch();
  3588.         if(ans==0)
  3589.         {
  3590.             ans2=getch();
  3591.             if(ans2==59)        /* F1 */
  3592.                 ans='H';
  3593.             else
  3594.             {
  3595.                 if(ans2=='G'||ans2=='H'||ans2=='I')cur_iy-=speed;
  3596.                 if(ans2=='I'||ans2=='M'||ans2=='Q')cur_ix+=speed;
  3597.                 if(ans2=='O'||ans2=='P'||ans2=='Q')cur_iy+=speed;
  3598.                 if(ans2=='O'||ans2=='K'||ans2=='G')cur_ix-=speed;
  3599.                 if(cur_iy<yc)cur_iy=yc;
  3600.                 if(cur_ix<xc)cur_ix=xc;
  3601.                 if(cur_iy>yc+ys-1)cur_iy=yc+ys-1;
  3602.                 if(cur_ix>xc+xs-1)cur_ix=xc+xs-1;
  3603.             }
  3604.         }
  3605.         if(ans=='h'||ans=='H')
  3606.         {
  3607.             txs=ScreenXs;
  3608.             ScreenXs=MaxXs;
  3609.             save_box(0,M.Back,Mbuff,
  3610.                 0,0,MaxXs,32/lsize);
  3611.             paint_box(0,M.Back,MT_Buff,0,0,ScreenXs,32/lsize);
  3612.             sprintf(String,
  3613. "(s)maller (l)arger 'Enter'=plot  'Esc'=exit without plotting");
  3614.             plot_font_h(M.White,1,1,String,FontSize,Font);
  3615.             ans=getch();
  3616.             unsave_box(0,M.Back,Mbuff,
  3617.                 0,0,MaxXs,32/lsize);
  3618.             ScreenXs=txs;
  3619.         }        
  3620.  
  3621.         if(ans=='l')cur_ps*=cur_scale;
  3622.         if(ans=='s')cur_ps/=cur_scale;
  3623.         if(cur_ps<MIN_PIX)cur_ps=MIN_PIX;
  3624.         if(ans=='-')
  3625.         {
  3626.             if(speed>1)
  3627.                 speed/=2;
  3628.             else
  3629.                 cur_scale=sqrt((double)cur_scale);
  3630.         }
  3631.         if(ans=='+'&&speed<256)speed*=2;
  3632.  
  3633.         unplotln(0,ix[0],iy[0]+1,ix[1],iy[1],MT_Buff[0]);
  3634.         unplotln(0,ix[1]+1,iy[1],ix[2],iy[2],MT_Buff[1]);
  3635.         unplotln(0,ix[2],iy[2]-1,ix[3],iy[3],MT_Buff[2]);
  3636.         unplotln(0,ix[3]-1,iy[3],ix[0],iy[0],MT_Buff[3]);
  3637.  
  3638.         xy_ll((double)cur_ix,(double)cur_iy,&dlat,&dlon);
  3639.         cur_clat=dlat;cur_clon=dlon;
  3640.         get_corners(xc,yc,xs,ys,
  3641.             m_ps,m_clat,m_clon,cur_ps,cur_clat,cur_clon,ix,iy);
  3642.  
  3643.         tplotln_val(0,ix[0],iy[0]+1,ix[1],iy[1],MT_Buff[0],M.White);
  3644.         tplotln_val(0,ix[1]+1,iy[1],ix[2],iy[2],MT_Buff[1],M.White);
  3645.         tplotln_val(0,ix[2],iy[2]-1,ix[3],iy[3],MT_Buff[2],M.White);
  3646.         tplotln_val(0,ix[3]-1,iy[3],ix[0],iy[0],MT_Buff[3],M.White);
  3647.  
  3648.     }while(ans!=83&&ans!=27&&ans!=13);
  3649.  
  3650.     unplotln(0,ix[0],iy[0]+1,ix[1],iy[1],MT_Buff[0]);
  3651.     unplotln(0,ix[1]+1,iy[1],ix[2],iy[2],MT_Buff[1]);
  3652.     unplotln(0,ix[2],iy[2]-1,ix[3],iy[3],MT_Buff[2]);
  3653.     unplotln(0,ix[3]-1,iy[3],ix[0],iy[0],MT_Buff[3]);
  3654.  
  3655.     M.Pixsize=*pixsize=cur_ps;
  3656.     M.Clat=*clat=cur_clat;
  3657.     M.Clon=*clon=cur_clon;
  3658.  
  3659.     if(cur_ps<20)
  3660.     {    
  3661.         *space=30.0;
  3662.         return(ans);
  3663.     }
  3664.     if(cur_ps<10)
  3665.     {    
  3666.         *space=15.0;
  3667.         return(ans);
  3668.     }
  3669.     if(cur_ps<2)
  3670.     {    
  3671.         *space=5.0;
  3672.         return(ans);
  3673.     }
  3674.     *space=1.0;
  3675.     return(ans);
  3676.  
  3677. }
  3678.  
  3679.  
  3680.  
  3681.  
  3682. /********************************************************************
  3683. **
  3684. **
  3685. **
  3686. ********************************************************************* */
  3687.  
  3688. void get_corners(xc,yc,xs,ys,m_pixsize,m_clat,m_clon,
  3689.         cur_pixsize,cur_clat,cur_clon,x,y)
  3690.  
  3691. int xc,yc,xs,ys;
  3692. float m_pixsize,m_clat,m_clon,cur_pixsize,cur_clat,cur_clon;
  3693. int x[4],y[4];
  3694.  
  3695. {
  3696.     int i,j,k;
  3697.     double lat[4],lon[4],dx,dy;
  3698.  
  3699.     miv.indat[0]=cur_pixsize;
  3700.     miv.indat[1]=cur_clat;
  3701.     miv.indat[2]=cur_clon;
  3702.     miv.indat[3]=cur_clon;
  3703.     miv.indat[4]=cur_clat+10;
  3704.     miv.indat[5]=cur_clat-10;
  3705.     map_pos.xc=xc;    
  3706.     map_pos.yc=yc;
  3707.     map_pos.xs=xs;
  3708.     map_pos.ys=ys;
  3709.     auto_set_cc(miv.type,miv.indat);
  3710.     
  3711.     xy_ll((double)xc,(double)yc,lat+0,lon+0);
  3712.     xy_ll((double)xc,(double)yc+ys-1,lat+1,lon+1);
  3713.     xy_ll((double)xc+xs-1,(double)yc+ys-1,lat+2,lon+2);
  3714.     xy_ll((double)xc+xs-1,(double)yc,lat+3,lon+3);
  3715.  
  3716.     miv.indat[0]=m_pixsize;
  3717.     miv.indat[1]=m_clat;
  3718.     miv.indat[2]=m_clon;
  3719.     miv.indat[3]=m_clon;
  3720.     miv.indat[4]=m_clat+10;
  3721.     miv.indat[5]=m_clat-10;
  3722.     map_pos.xc=xc;    
  3723.     map_pos.yc=yc;
  3724.     map_pos.xs=xs;
  3725.     map_pos.ys=ys;
  3726.     auto_set_cc(miv.type,miv.indat);
  3727.  
  3728.     for(i=0;i<4;i++)
  3729.     {
  3730.         ll_xy(&dx,&dy,lat[i],lon[i]);
  3731.         x[i]=dx;
  3732.         y[i]=dy;
  3733.     }
  3734. }
  3735.  
  3736.  
  3737.  
  3738.  
  3739. /********************************************************************
  3740. **
  3741. **
  3742. **
  3743. ********************************************************************* */
  3744.  
  3745. int plot_map(xc,yc,xs,ys,pixsize,clat,clon,space,iop)
  3746.  
  3747. int xc,yc,xs,ys,iop;
  3748. float pixsize,clat,clon,space;
  3749.  
  3750. {
  3751.     int i,j,k,l,m;
  3752.     double sp=space;
  3753.     int num,val,filled=0;
  3754.     int ix=ScreenXs/2,iy=ScreenYs/2,speed=16;
  3755.  
  3756.     if(M.Out==1&&Fpout)
  3757.         fprintf(Fpout,"\npixsize = %6.3f  clat = %12.5f  clon = %12.5f\n",
  3758.             pixsize,clat,clon);
  3759.  
  3760.     miv.type=M.Type;
  3761.     miv.indat[0]=pixsize;
  3762.     miv.indat[1]=clat;
  3763.     miv.indat[2]=clon;
  3764.     miv.indat[3]=clon;
  3765.     miv.indat[4]=clat+10;
  3766.     miv.indat[5]=clat-10;
  3767.     map_pos.xc=xc;    
  3768.     map_pos.yc=yc;
  3769.     map_pos.xs=xs;
  3770.     map_pos.ys=ys;
  3771.     auto_set_cc(miv.type,miv.indat);
  3772.     screen_mm();
  3773.  
  3774.     if(iop==0)
  3775.     {
  3776.         paint_box(0,M.Back,MT_Buff,0,0,ScreenXs,ScreenYs);
  3777.         if(pixsize>5.0)
  3778.         {
  3779.             sp=10;
  3780.             if(M.Fill_In==0)
  3781.                 plot_graticule(Font,M.Grat,M.LatLon,sp,M.GratOn);
  3782.         }
  3783.         if(pixsize>2.5&&pixsize<=5.0)
  3784.         {
  3785.             sp=5;
  3786.             if(M.Fill_In==0)
  3787.                 plot_graticule(Font,M.Grat,M.LatLon,sp,M.GratOn);
  3788.         }
  3789.         if(pixsize<=2.5&&pixsize>0.5)
  3790.         {
  3791.             sp=1;
  3792.             if(M.Fill_In==0)
  3793.                 plot_graticule(Font,M.Grat,M.LatLon,sp,M.GratOn);
  3794.         }
  3795.         if(pixsize<=0.5&&pixsize>0.25)
  3796.         {
  3797.             sp=0.5;                                    
  3798.             if(M.Fill_In==0)
  3799.                 plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
  3800.         }
  3801.         if(pixsize<=0.25&&pixsize>0.05)
  3802.         {
  3803.             sp=0.1;
  3804.             if(M.Fill_In==0)
  3805.                 plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
  3806.         }
  3807.         if(pixsize<=0.05&&pixsize>0.025)
  3808.         {
  3809.             sp=0.05;
  3810.             if(M.Fill_In==0)
  3811.                 plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
  3812.         }
  3813.         if(pixsize<=0.025&&pixsize>0.005)
  3814.         {
  3815.             sp=0.01;
  3816.             if(M.Fill_In==0)
  3817.                 plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
  3818.         }
  3819.         if(pixsize<=0.005&&pixsize>0.0025)
  3820.         {
  3821.             sp=0.005;
  3822.             if(M.Fill_In==0)
  3823.                 plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
  3824.         }
  3825.         if(pixsize<=0.0025)
  3826.         {
  3827.             sp=0.001;
  3828.             if(M.Fill_In==0)
  3829.                 plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
  3830.         }
  3831.         if(iop==0)
  3832.         {
  3833.             for(i=0;i<M.Num_Type;i++)
  3834.             {
  3835.                 for(j=0;j<M.Ns[i];j++)
  3836.                 {
  3837.                     if(M.MapFile[i][j].max_pix*PixScale>pixsize
  3838.                         &&M.MapFile[i][j].min_pix*PixScale<=pixsize
  3839.                         &&M.Mm[i]==1)
  3840.                     {
  3841.                         if(kbhit()>0)
  3842.                         {
  3843.                             val=getch();
  3844.                             if(val==27)
  3845.                                 return(-1);
  3846.                         }
  3847.                         num=convert_bin(M.MapFile[i][j].color,
  3848.                                 M.MapFile[i][j].filename);
  3849.                         if(num<-1)
  3850.                             return(-2);
  3851.                         if(M.Out==1&&Fpout)
  3852.                             fprintf(Fpout,"%s -- color = %d plotted %d segments\n",
  3853.                                 M.MapFile[i][j].filename,M.MapFile[i][j].color,num);
  3854.                     }
  3855.                 }
  3856.                 if(M.Fill_In>0&&i==M.Fill_After&&M.Mm[i]==1)
  3857.                 {
  3858.                     filled=0;
  3859.                     for(m=0;m<M.Num_Fill;m++)
  3860.                     {
  3861.                         if(M.FI_max[m]*PixScale>pixsize&&
  3862.                                         M.FI_min[m]*PixScale<=pixsize)
  3863.                         {
  3864.                             num=fill_in_area(M.Fill_In_Name[m]);
  3865.                             if(num<-1)
  3866.                                 return(-2);
  3867.                             filled=1;
  3868.                         }
  3869.                     }
  3870.                     if(filled==1)
  3871.                     {
  3872.                         save_box(0,M.Black,Mbuff,0,0,MaxXs,36/FontSize);
  3873.                         sprintf(String,
  3874. "You are in 'cursor mode', hit any key to continue or F1 for help.");
  3875.                 plot_font_h(M.White,10/FontSize,5/FontSize,String,FontSize,Font);
  3876.                         if(getch()==0)
  3877.                             getch();
  3878.                         unsave_box(0,M.Black,Mbuff,0,0,MaxXs,36/FontSize);
  3879.                         pix_loc(ix,iy,&ix,&iy,&speed);
  3880.                     }
  3881.                 }
  3882.             }
  3883.             for(i=0;i<M.NumSymbol;i++)
  3884.             {
  3885.                 if(PlaceFile[i].on==1&&
  3886.                     pixsize>=PlaceFile[i].min_pix&&pixsize<PlaceFile[i].max_pix)
  3887.                 {
  3888.                     symbol_plot(i,0);
  3889.                 }
  3890.             }
  3891.         }
  3892.     }
  3893. }
  3894.  
  3895. /**************************************************************************
  3896. **
  3897. **        iop = 0 -- plot only symbols
  3898. **                1 -- names
  3899. **                2 -- id
  3900. **
  3901. ************************************************************************* */
  3902.  
  3903. int symbol_plot(i,iop)
  3904.  
  3905. int i,iop;
  3906.  
  3907. {
  3908.     int j,k,u,v;
  3909.     int val;
  3910.     FILE *fploc;
  3911.     char string[STR_LEN],id[STR_LEN],name[STR_LEN];
  3912.     double lat,lon,x,y;
  3913.     int ix,iy,ss=SYM_SIZE/2;
  3914.     char *result;
  3915.  
  3916.     fploc=open_to_read_binary(PlaceFile[i].filename);
  3917.     if(fploc)
  3918.     {
  3919.         while((result=fgets(string,80,fploc))!=NULL)
  3920.         {
  3921.             string[strlen(string)-1]='\0';
  3922.             if(sscanf(string,"%s%lf%lf%s",name,&lat,&lon,id)!=4)
  3923.             {
  3924.                 fclose(fploc);
  3925.                 return(-1);
  3926.             }
  3927.             ll_xy(&x,&y,lat,lon);
  3928.             ix=x,iy=y;
  3929.             if(ix>=0&&ix<ScreenXs&&iy>=0&&iy<ScreenYs)
  3930.             {
  3931.                 if(iop==0)
  3932.                 {
  3933.                     for(u=0;u<SYM_SIZE;u++)
  3934.                     {
  3935.                         for(v=0;v<SYM_SIZE;v++)
  3936.                         {
  3937.                             if(PlaceFile[i].Symbol[u][v]=='*')
  3938.                                 plotpt(0,ix-ss+v,iy-ss+u,PlaceFile[i].color);
  3939.                         }
  3940.                     }
  3941.                 }
  3942.                 if(iop==1)
  3943.                     plot_font_h(M.White,ix-ss-strlen(name)*7,
  3944.                         iy-ss+2,name,2,Font);
  3945.                 if(iop==2)
  3946.                     plot_font_h(M.White,ix+ss+2,iy-ss+2,id,2,Font);
  3947.             }
  3948.         }
  3949.     }
  3950.     fclose(fploc);
  3951. }
  3952.  
  3953. /**************************************************************************
  3954. **
  3955. **
  3956. **
  3957. ************************************************************************* */
  3958.  
  3959. int fill_in_area(filename)
  3960.  
  3961. char *filename;
  3962.  
  3963. {
  3964.     int i,j,k,p;
  3965.     int idc[2],val1,val2;
  3966.     double lat,lon;
  3967.     FILE *fpblb;
  3968.     double x,y;
  3969.     int ix,iy,num;
  3970.     char pth[STR_LEN],nam[10],typ[10],string[STR_LEN];
  3971.  
  3972.     fpblb=open_to_read_binary(filename);
  3973.     split(filename,pth,nam,typ);
  3974.     if(!fpblb)
  3975.         return(0);
  3976.     while(fread((char *)idc,sizeof(int),2,fpblb)==2)
  3977.     {
  3978.         fread((char *)&lat,sizeof(double),1,fpblb);
  3979.         fread((char *)&lon,sizeof(double),1,fpblb);
  3980.         ll_xy(&x,&y,lat,lon);
  3981.         ix=x;iy=y;
  3982.         if(ix>=0&&ix<ScreenXs&&iy>=0&&iy<ScreenYs)
  3983.         {
  3984.             if(getpt(0,ix,iy)==M.Back)
  3985.             {
  3986.                 if(VideoType=='X'||VideoType=='S'||VideoType=='Y')
  3987.                 {
  3988.                     num=auto_fill_in(0,idc[1]+16,Mbuff,todo,ix,iy);
  3989.                     if(num<-1)
  3990.                         return(-2);
  3991.                 }
  3992.                 else
  3993.                 {
  3994.                     val1=M.Fill_Color[idc[1]][0];
  3995.                     val2=M.Fill_Color[idc[1]][1];
  3996.                     if(val1==M.Back)
  3997.                         val1=M.Black;
  3998.                     if(val2==M.Back)
  3999.                         val2=M.Black;
  4000.                     num=auto_fill_in_2(0,val1,val2,Mbuff,todo,ix,iy);
  4001.                     if(num<-1)
  4002.                         return(-2);
  4003.                 }
  4004.             }
  4005.             else if(getpt(0,ix,iy)!=idc[1]+16)
  4006.             {
  4007.                 if(VideoType=='X'||VideoType=='S'||VideoType=='Y')
  4008.                     plotpt(0,ix,iy,idc[1]+16);
  4009.                 else
  4010.                 {
  4011.                     if((ix+iy)%2==0)
  4012.                     {
  4013.                         val1=M.Fill_Color[idc[1]][0];
  4014.                         plotpt(0,ix,iy,val1);
  4015.                     }
  4016.                     else
  4017.                     {
  4018.                         val2=M.Fill_Color[idc[1]][1];
  4019.                         plotpt(0,ix,iy,val2);
  4020.                     }
  4021.                 }
  4022.             }
  4023.         }
  4024.     }
  4025.     fclose(fpblb);
  4026.     return(1);
  4027. }
  4028.  
  4029.  
  4030.  
  4031.  
  4032. /********************************************************************
  4033. **
  4034. **
  4035. **
  4036. ********************************************************************* */
  4037.  
  4038. void save_rectangle(xc,yc,xs,ys,fp)
  4039.  
  4040. int xc,yc,xs,ys;
  4041. FILE *fp;
  4042.  
  4043. {
  4044.     int i,j,k;
  4045.  
  4046.     rewind(fp);
  4047.  
  4048.     fwrite((char *)&ys,sizeof(int),1,fp);
  4049.     fwrite((char *)&xs,sizeof(int),1,fp);
  4050.     for(i=0;i<ys;i++)
  4051.     {
  4052.         getrow(0,xc,xc+xs-1,i+yc,MT_Buff);
  4053.         fwrite((char *)MT_Buff,sizeof(char),xs,fp);
  4054.     }
  4055. }
  4056.  
  4057. /********************************************************************
  4058. **
  4059. **
  4060. **
  4061. ********************************************************************* */
  4062.  
  4063. void recall_rectangle(xc,yc,xs,ys,fp)
  4064.  
  4065. int xc,yc,xs,ys;
  4066. FILE *fp;
  4067.  
  4068. {
  4069.     int i,j,k;
  4070.  
  4071.     rewind(fp);
  4072.     fread((char *)&ys,sizeof(int),1,fp);
  4073.     fread((char *)&xs,sizeof(int),1,fp);
  4074.     if(xc+xs>ScreenXs)xc=ScreenXs-xs;
  4075.     if(yc+ys>ScreenYs)yc=ScreenYs-ys;
  4076.     if(xc<0||yc<0)return;
  4077.  
  4078.     for(i=0;i<ys;i++)
  4079.     {
  4080.         fread((char *)MT_Buff,sizeof(char),xs,fp);
  4081.         plotrow(1,xc,xc+xs-1,i+yc,MT_Buff);
  4082.     }
  4083. }
  4084.  
  4085.  
  4086. /********************************************************************
  4087. **
  4088. **
  4089. **
  4090. ********************************************************************* */
  4091.  
  4092. void screen_mm()
  4093.  
  4094. {
  4095.     double lat,lon,x,y;
  4096.     double sx=ScreenXs,sy=ScreenYs;
  4097.     float flat,flon,lon_r,lon_l;
  4098.  
  4099.     MaxLat=-360.0;
  4100.     MaxLon=-360.0;
  4101.     MinLat= 360.0;
  4102.     MinLon= 360.0;
  4103.  
  4104.     x=0.0;y=0.0;
  4105.     xy_ll(x,y,&lat,&lon);
  4106.     flat=lat;flon=lon;
  4107.     if(flat>MaxLat)MaxLat=flat;
  4108.     if(flon>MaxLon)MaxLon=flon;
  4109.     if(flat<MinLat)MinLat=flat;
  4110.     if(flon<MinLon)MinLon=flon;
  4111.     x=0.0;y=ScreenYs/2.0;
  4112.     xy_ll(x,y,&lat,&lon);lon_l=lon;
  4113.     flat=lat;flon=lon;
  4114.     if(flat>MaxLat)MaxLat=flat;
  4115.     if(flon>MaxLon)MaxLon=flon;
  4116.     if(flat<MinLat)MinLat=flat;
  4117.     if(flon<MinLon)MinLon=flon;
  4118.     x=0.0;y=ScreenYs;
  4119.     xy_ll(x,y,&lat,&lon);
  4120.     flat=lat;flon=lon;
  4121.     if(flat>MaxLat)MaxLat=flat;
  4122.     if(flon>MaxLon)MaxLon=flon;
  4123.     if(flat<MinLat)MinLat=flat;
  4124.     if(flon<MinLon)MinLon=flon;
  4125.     x=320.0;y=ScreenYs;
  4126.     xy_ll(x,y,&lat,&lon);
  4127.     flat=lat;flon=lon;
  4128.     if(flat>MaxLat)MaxLat=flat;
  4129.     if(flon>MaxLon)MaxLon=flon;
  4130.     if(flat<MinLat)MinLat=flat;
  4131.     if(flon<MinLon)MinLon=flon;
  4132.     x=ScreenXs;y=ScreenYs;
  4133.     xy_ll(x,y,&lat,&lon);
  4134.     flat=lat;flon=lon;
  4135.     if(flat>MaxLat)MaxLat=flat;
  4136.     if(flon>MaxLon)MaxLon=flon;
  4137.     if(flat<MinLat)MinLat=flat;
  4138.     if(flon<MinLon)MinLon=flon;
  4139.     x=ScreenXs;y=ScreenXs/2;
  4140.     xy_ll(x,y,&lat,&lon);lon_r=lon;
  4141.     flat=lat;flon=lon;
  4142.     if(flat>MaxLat)MaxLat=flat;
  4143.     if(flon>MaxLon)MaxLon=flon;
  4144.     if(flat<MinLat)MinLat=flat;
  4145.     if(flon<MinLon)MinLon=flon;
  4146.     x=ScreenXs;y=  0.0;
  4147.     xy_ll(x,y,&lat,&lon);
  4148.     flat=lat;flon=lon;
  4149.     if(flat>MaxLat)MaxLat=flat;
  4150.     if(flon>MaxLon)MaxLon=flon;
  4151.     if(flat<MinLat)MinLat=flat;
  4152.     if(flon<MinLon)MinLon=flon;
  4153.     x=ScreenXs/2;y=  0.0;
  4154.     xy_ll(x,y,&lat,&lon);
  4155.     flat=lat;flon=lon;
  4156.     if(flat>MaxLat)MaxLat=flat;
  4157.     if(flon>MaxLon)MaxLon=flon;
  4158.     if(flat<MinLat)MinLat=flat;
  4159.     if(flon<MinLon)MinLon=flon;
  4160.     if(lon_l>180.0)
  4161.         lon_l-=360.0;
  4162.     if(lon_r>180.0)
  4163.         lon_r-=360.0;
  4164.  
  4165.     lat=-89.999;    /* south pole check */
  4166.     ll_xy(&x,&y,lat,lon);
  4167.     if(x>=0.0&&x<sx&&y>0.0&&y<sy)
  4168.     {        
  4169.         MinLat=-90.001;
  4170.         MinLon=-360.0;
  4171.         MaxLon= 360.0;
  4172.     }
  4173.     lat=89.999;    /* north pole check */
  4174.     ll_xy(&x,&y,lat,lon);
  4175.     if(x>=0.0&&x<sx&&y>0.0&&y<sy)
  4176.     {        
  4177.         MaxLat= 90.001;
  4178.         MinLon=-360.0;
  4179.         MaxLon= 360.0;
  4180.     }
  4181.     if(lon_l>lon_r)    /* date line on screen */
  4182.     {
  4183.         MinLon=-360.0;
  4184.         MaxLon= 360.0;
  4185.     }
  4186. }
  4187.  
  4188.  
  4189. /***********************************************************************
  4190. **
  4191. **
  4192. **
  4193. ***********************************************************************/
  4194. int auto_fill_in(hue,val,buffer,todo,cx,cy)
  4195.  
  4196. int todo[2][MAXDO];
  4197. int hue,val;
  4198. unsigned char *buffer;
  4199. int cx,cy;
  4200.  
  4201. {
  4202.     int i,j,k,m,n,l;
  4203.     int x=cx,y=cy,on=0;
  4204.     int lastup[2],lastdn[2];
  4205.     int fillval,cval,kbval;
  4206.  
  4207.     fillval=getpt(hue,x,y);
  4208.     if(fillval==val)return(-1);
  4209.  
  4210.     do
  4211.     {
  4212.         if(kbhit()>0)
  4213.         {
  4214.             kbval=getch();
  4215.             if(kbval==27)
  4216.                 return(-2);
  4217.         }
  4218.         lastup[0]=lastup[1]=lastdn[0]=lastdn[1]=-1;
  4219.         for(i=x;i<ScreenXs;i++)
  4220.         {
  4221.             if(i>=ScreenXs||getpt(hue,i,y)!=fillval)
  4222.                 break;
  4223.             plotpt(hue,i,y,val);
  4224.             on=check_point(hue,i,y,fillval,on,todo);
  4225.             if(y>0&&getpt(hue,i,y-1)==fillval)
  4226.             {
  4227.                 lastup[0]=i;
  4228.                 lastup[1]=y-1;
  4229.             }
  4230.             if(i<ScreenXs-1&&getpt(hue,i,y+1)==fillval)
  4231.             {
  4232.                 lastdn[0]=i;
  4233.                 lastdn[1]=y+1;
  4234.             }
  4235.         }
  4236.         if(lastup[0]>=0&&on<MAXDO)
  4237.         {
  4238.             todo[0][on]=lastup[0];
  4239.             todo[1][on]=lastup[1];
  4240.             on+=1;
  4241.         }
  4242.         if(lastdn[0]>=0&&on<MAXDO)
  4243.         {
  4244.             todo[0][on]=lastdn[0];
  4245.             todo[1][on]=lastdn[1];
  4246.             on+=1;
  4247.         }
  4248.         lastup[0]=lastup[1]=lastdn[0]=lastdn[1]=-1;
  4249.         if(x>0)
  4250.         {
  4251.             for(i=x-1;i>=0;i--)
  4252.             {
  4253.                 if(i<0||getpt(hue,i,y)!=fillval)
  4254.                     break;
  4255.                 plotpt(hue,i,y,val);
  4256.                 on=check_point(hue,i,y,fillval,on,todo);
  4257.                 if(y>0&&getpt(hue,i,y-1)==fillval)
  4258.                 {
  4259.                     lastup[0]=i;
  4260.                     lastup[1]=y-1;
  4261.                 }
  4262.                 if(i<ScreenXs-1&&getpt(hue,i,y+1)==fillval)
  4263.                 {
  4264.                     lastdn[0]=i;
  4265.                     lastdn[1]=y+1;
  4266.                 }
  4267.             }
  4268.         }
  4269.         if(lastup[0]>=0&&on<MAXDO)
  4270.         {
  4271.             todo[0][on]=lastup[0];
  4272.             todo[1][on]=lastup[1];
  4273.             on+=1;
  4274.         }
  4275.         if(lastdn[0]>=0&&on<MAXDO)
  4276.         {
  4277.             todo[0][on]=lastdn[0];
  4278.             todo[1][on]=lastdn[1];
  4279.             on+=1;
  4280.         }
  4281.         on=purge(hue,fillval,todo,on);
  4282.         if(on>0)
  4283.         {
  4284.             x=todo[0][on-1];
  4285.             y=todo[1][on-1];
  4286.         }
  4287.     }while(on>0);
  4288. }
  4289.  
  4290. /***********************************************************************
  4291. **
  4292. **
  4293. **
  4294. ***********************************************************************/
  4295.  
  4296. int auto_fill_in_2(hue,val1,val2,buffer,todo,cx,cy)
  4297.  
  4298. int todo[2][MAXDO];
  4299. int hue,val1,val2;
  4300. unsigned char *buffer;
  4301. int cx,cy;
  4302.  
  4303. {
  4304.     int i,j,k,m,n,l;
  4305.     int x=cx,y=cy,on=0;
  4306.     int lastup[2],lastdn[2];
  4307.     int fillval,cval,kbval;
  4308.  
  4309.     fillval=getpt(hue,x,y);
  4310.     if(fillval==val1||fillval==val2)
  4311.         return(-1);
  4312.     do
  4313.     {
  4314.         if(kbhit()>0)
  4315.         {
  4316.             kbval=getch();
  4317.             if(kbval==27)
  4318.                 return(-2);
  4319.         }
  4320.         lastup[0]=lastup[1]=lastdn[0]=lastdn[1]=-1;
  4321.         for(i=x;i<ScreenXs;i++)
  4322.         {
  4323.             if(i>=ScreenXs||getpt(hue,i,y)!=fillval)
  4324.                 break;
  4325.             if(((i+y)%2)==0)
  4326.                 plotpt(hue,i,y,val1);
  4327.             else
  4328.                 plotpt(hue,i,y,val2);
  4329.             on=check_point(hue,i,y,fillval,on,todo);
  4330.             if(y>0&&getpt(hue,i,y-1)==fillval)
  4331.             {
  4332.                 lastup[0]=i;
  4333.                 lastup[1]=y-1;
  4334.             }
  4335.             if(i<ScreenXs-1&&getpt(hue,i,y+1)==fillval)
  4336.             {
  4337.                 lastdn[0]=i;
  4338.                 lastdn[1]=y+1;
  4339.             }
  4340.         }
  4341.         if(lastup[0]>=0&&on<MAXDO)
  4342.         {
  4343.             todo[0][on]=lastup[0];
  4344.             todo[1][on]=lastup[1];
  4345.             on+=1;
  4346.         }
  4347.         if(lastdn[0]>=0&&on<MAXDO)
  4348.         {
  4349.             todo[0][on]=lastdn[0];
  4350.             todo[1][on]=lastdn[1];
  4351.             on+=1;
  4352.         }
  4353.         lastup[0]=lastup[1]=lastdn[0]=lastdn[1]=-1;
  4354.         if(x>0)
  4355.         {
  4356.             for(i=x-1;i>=0;i--)
  4357.             {
  4358.                 if(i<0||getpt(hue,i,y)!=fillval)
  4359.                     break;
  4360.                 if(((i+y)%2)==0)
  4361.                     plotpt(hue,i,y,val1);
  4362.                 else
  4363.                     plotpt(hue,i,y,val2);
  4364.                 on=check_point(hue,i,y,fillval,on,todo);
  4365.                 if(y>0&&getpt(hue,i,y-1)==fillval)
  4366.                 {
  4367.                     lastup[0]=i;
  4368.                     lastup[1]=y-1;
  4369.                 }
  4370.                 if(i<ScreenXs-1&&getpt(hue,i,y+1)==fillval)
  4371.                 {
  4372.                     lastdn[0]=i;
  4373.                     lastdn[1]=y+1;
  4374.                 }
  4375.             }
  4376.         }
  4377.         if(lastup[0]>=0&&on<MAXDO)
  4378.         {
  4379.             todo[0][on]=lastup[0];
  4380.             todo[1][on]=lastup[1];
  4381.             on+=1;
  4382.         }
  4383.         if(lastdn[0]>=0&&on<MAXDO)
  4384.         {
  4385.             todo[0][on]=lastdn[0];
  4386.             todo[1][on]=lastdn[1];
  4387.             on+=1;
  4388.         }
  4389.         on=purge(hue,fillval,todo,on);
  4390.         if(on>0)
  4391.         {
  4392.             x=todo[0][on-1];
  4393.             y=todo[1][on-1];
  4394.         }
  4395.     }while(on>0);
  4396. }
  4397.  
  4398.  
  4399. /***********************************************************************
  4400. **
  4401. **
  4402. **
  4403. ***********************************************************************/
  4404.  
  4405. int convert_bin(val,region)
  4406.  
  4407. char *region;
  4408. int val;
  4409.  
  4410. {
  4411.     int i,j,k,m,n=0,p;
  4412.     double x,y,xo,yo;
  4413.     int ix,iy,ixo=-1,iyo=-1;
  4414.     double dx,dy,dist;
  4415.     int secnum,numpt,numsec,ival;
  4416.     FILE *fp,*fphdr,*fpatr;
  4417.     float latlon[2],mll[4],mnln,mxln,mnlt,mxlt;
  4418.     char string[40],pth[40],name[40],type[40];
  4419.     int doit,numplot=0;
  4420.     int first_seg=-1,last_seg=-1,atr=1;
  4421.     long offset,attrib;
  4422.  
  4423.     strcpy(string,region);
  4424.     strcat(string,".bin");
  4425.     fp=open_to_read_binary(string);
  4426.     if(!fp)
  4427.     {
  4428.         if(M.Out==1&&Fpout)
  4429.             fprintf(Fpout,"could not open '%s'\n",string);
  4430.         return(-1);
  4431.     }
  4432. /*    setbuf(fp,Inbuff);*/
  4433.     strcpy(string,region);
  4434.     strcat(string,".hdr");
  4435.     fphdr=open_to_read_binary(string);
  4436.     if(!fphdr)
  4437.     {
  4438.         if(M.Out==1&&Fpout)
  4439.             fprintf(Fpout,"could not open '%s'\n",string);
  4440.         fclose(fp);
  4441.         return(-1);
  4442.     }
  4443. /*    setbuf(fphdr,Inbuff2);*/
  4444.     fread((char *)&numsec,sizeof(int),1,fphdr);
  4445.     fread((char *)&numsec,sizeof(int),1,fp);
  4446.     for(j=0;j<numsec;j++)
  4447.     {
  4448.         if(kbhit()>0)
  4449.         {
  4450.             ival=getch();
  4451.             if(ival==27)
  4452.             {
  4453.                 fclose(fp);
  4454.                 fclose(fphdr);
  4455.                 return(-2);
  4456.             }
  4457.         }
  4458.         fread((char *)&offset,sizeof(long),1,fphdr);
  4459.         fread((char *)mll,sizeof(float),4,fphdr);
  4460.         doit=1;
  4461.         mnln=mll[0];mxln=mll[1];mnlt=mll[2];mxlt=mll[3];
  4462.         if(mnln>MaxLon||mnlt>MaxLat||mxln<MinLon||mxlt<MinLat)
  4463.             doit=0;
  4464.         if(doit==1)
  4465.         {
  4466.             numplot+=1;
  4467.             fseek(fp,offset,SEEK_SET);
  4468.             fread((char *)&numpt,sizeof(int),1,fp);
  4469.             fread((char *)mll,sizeof(float),4,fp);
  4470.             m=0;
  4471.             for(i=0;i<numpt;i++)
  4472.             {
  4473.                 fread((char *)latlon,sizeof(float),2,fp);
  4474.                 if(doit==1)
  4475.                 {
  4476.                     ll_xy(&x,&y,(double)latlon[0],(double)latlon[1]);
  4477.                     if(i==0)
  4478.                     {
  4479.                         xo=x;yo=y;
  4480.                         ixo=ix;iyo=iy;
  4481.                     }
  4482.                     ix=x;iy=y;
  4483.                     dist=(xo-x)*(xo-x)+(yo-y)*(yo-y);
  4484.                     if(dist<1000000.0)
  4485.                     {
  4486.                         plotpt(0,ix,iy,val);
  4487.                         if(i>0)
  4488.                             plotln(0,ix,iy,ixo,iyo,val);
  4489.                         ixo=ix;iyo=iy;
  4490.                         xo=ix;yo=iy;
  4491.                     }
  4492.                 }
  4493.             }
  4494.         }
  4495.     }
  4496.     fclose(fp);
  4497.     fclose(fphdr);
  4498.     return(numplot);
  4499. }
  4500.  
  4501. /**************************************************************************
  4502. **
  4503. **
  4504. **
  4505. ************************************************************************* */
  4506.  
  4507. int split(string,path,name,type)
  4508.  
  4509. char *string,*path,*name,*type;
  4510.  
  4511. {
  4512.     int i,j,k;
  4513.     int dot=-1,last_slash=-1,len=strlen(string),num=0;
  4514.  
  4515.     if(strlen(string)>STR_LEN)
  4516.     {
  4517.         SetVideoMode(0,&B_Id);
  4518.         printf("In split() -- string 1 too long!\n\n");
  4519.         exit(0);
  4520.     }
  4521.  
  4522.     for(i=0;i<len;i++)
  4523.     {
  4524.         if(string[i]=='.')
  4525.             dot=i;
  4526.         if(string[i]=='\\')
  4527.             last_slash=i;
  4528.     }
  4529.     last_slash+=1;
  4530.     if(dot==-1)
  4531.         dot=len-1;
  4532.     if(last_slash>0)
  4533.     {
  4534.         for(i=0;i<last_slash;i++)
  4535.             path[i]=string[i];
  4536.     }
  4537.     path[last_slash]='\0';
  4538.     for(i=last_slash;i<dot;i++)
  4539.         name[i-last_slash]=string[i];
  4540.     name[dot-last_slash]='\0';
  4541.     dot+=1;
  4542.     for(i=dot;i<len;i++)
  4543.         type[i-dot]=string[i];
  4544.     type[len-dot]='\0';
  4545.     if(strlen(name)>0)
  4546.         num+=1;
  4547.     if(strlen(type)>0)
  4548.         num+=1;
  4549.  
  4550.     return(num);
  4551. }
  4552.  
  4553.  
  4554. /********************************************************************
  4555. **
  4556. **
  4557. **
  4558. ********************************************************************* */
  4559.  
  4560. void fill_voids()
  4561.  
  4562. {
  4563.     int i,j,k;
  4564.     int val;
  4565.     int xc=240,yc=240,xs=32,ys=32;
  4566.     int x1=xc-1,x2=xc+xs,speed=8;
  4567.     int num,min;
  4568.  
  4569.     if(x1<0)x1=0;
  4570.     if(x2>ScreenXs-1)x2=ScreenXs-1;
  4571.  
  4572.     printf("Give minimum number of neighbors to fill with.\n");
  4573.     scanf("%d",&min);
  4574.  
  4575.     do
  4576.     {
  4577.         limit_area(&xc,&yc,&xs,&ys,&speed,ScreenXs,1,MT_Buff);
  4578.  
  4579.         for(i=yc;i<yc+2;i++)    /* load first 2 rows */
  4580.             getrow(0,xc,xc+xs-1,i,MT_Buff[i%3]);
  4581.         for(i=yc+1;i<yc+ys-1;i++)
  4582.         {
  4583.             getrow(0,xc,xc+xs-1,i+1,MT_Buff[(i+1)%3]);
  4584.             MT_Buff[3][0]=MT_Buff[i%3][0];
  4585.             MT_Buff[3][xs-1]=MT_Buff[i%3][xs-1];
  4586.             for(j=1;j<xs-1;j++)
  4587.             {
  4588.                 if(MT_Buff[i%3][j]==0)
  4589.                 {
  4590.                     num=0;
  4591.                     if(MT_Buff[(i-1)%3][j-1]!=0)num+=1;
  4592.                     if(MT_Buff[(i-1)%3][j]!=0)num+=1;
  4593.                     if(MT_Buff[(i-1)%3][j+1]!=0)num+=1;
  4594.                     if(MT_Buff[(i)%3][j-1]!=0)num+=1;
  4595.                     if(MT_Buff[(i)%3][j+1]!=0)num+=1;
  4596.                     if(MT_Buff[(i+1)%3][j-1]!=0)num+=1;
  4597.                     if(MT_Buff[(i+1)%3][j]!=0)num+=1;
  4598.                     if(MT_Buff[(i+1)%3][j+1]!=0)num+=1;
  4599.  
  4600.                     if(num>=min)
  4601.                     {
  4602.                         if(MT_Buff[(i-1)%3][j+1]!=0)
  4603.                             MT_Buff[3][j]=MT_Buff[(i-1)%3][j+1];
  4604.                         else if(MT_Buff[(i-1)%3][j]!=0)
  4605.                             MT_Buff[3][j]=MT_Buff[(i-1)%3][j];
  4606.                         else if(MT_Buff[i%3][j+1]!=0)
  4607.                             MT_Buff[3][j]=MT_Buff[i%3][j+1];
  4608.                         else if(MT_Buff[(i-1)%3][j-1]!=0)
  4609.                             MT_Buff[3][j]=MT_Buff[(i-1)%3][j-1];
  4610.                         else if(MT_Buff[(i+1)%3][j+1]!=0)
  4611.                             MT_Buff[3][j]=MT_Buff[(i-1)%3][j-1];
  4612.                         else if(MT_Buff[(i)%3][j-1]!=0)
  4613.                             MT_Buff[3][j]=MT_Buff[(i-1)%3][j-1];
  4614.                         else if(MT_Buff[(i+1)%3][j]!=0)
  4615.                             MT_Buff[3][j]=MT_Buff[(i-1)%3][j-1];
  4616.                         else if(MT_Buff[(i+1)%3][j-1]!=0)
  4617.                             MT_Buff[3][j]=MT_Buff[(i-1)%3][j-1];
  4618.                     }
  4619.                 }
  4620.                 else
  4621.                     MT_Buff[3][j]=MT_Buff[i%3][j];
  4622.             }
  4623.             plotrow(0,xc,xc+xs-1,i,MT_Buff[3]);
  4624.         }
  4625.         printf("Again?\n");
  4626.     }while(getch()!='n');
  4627. }
  4628.  
  4629.  
  4630. /********************************************************************
  4631. **
  4632. **
  4633. **
  4634. ********************************************************************* */
  4635.  
  4636. void remove_boundaries(val)
  4637.  
  4638. int val;
  4639.  
  4640. {
  4641.     int i,j,k;
  4642.     int xc=0,yc=0,xs=ScreenXs,ys=ScreenYs;
  4643.     int x1=xc-1,x2=xc+xs;
  4644.  
  4645.     if(x1<0)x1=0;
  4646.     if(x2>ScreenXs-1)x2=ScreenXs-1;
  4647.  
  4648.     for(i=yc;i<yc+2;i++)    /* load first 2 rows */
  4649.         getrow(0,xc,xc+xs-1,i,MT_Buff[i%3]);
  4650.     for(i=yc+1;i<yc+ys-1;i++)
  4651.     {
  4652.         getrow(0,xc,xc+xs-1,i+1,MT_Buff[(i+1)%3]);
  4653.         MT_Buff[3][0]=MT_Buff[i%3][0];
  4654.         MT_Buff[3][xs-1]=MT_Buff[i%3][xs-1];
  4655.         for(j=1;j<xs-1;j++)
  4656.         {
  4657.             if(MT_Buff[i%3][j]==val)
  4658.             {
  4659.                 if(MT_Buff[(i-1)%3][j+1]!=val)
  4660.                     MT_Buff[3][j]=MT_Buff[(i-1)%3][j+1];
  4661.                 else if(MT_Buff[(i-1)%3][j]!=val)
  4662.                     MT_Buff[3][j]=MT_Buff[(i-1)%3][j];
  4663.                 else if(MT_Buff[i%3][j+1]!=val)
  4664.                     MT_Buff[3][j]=MT_Buff[i%3][j+1];
  4665.                 else if(MT_Buff[(i-1)%3][j-1]!=val)
  4666.                     MT_Buff[3][j]=MT_Buff[(i-1)%3][j-1];
  4667.             }
  4668.             else
  4669.                 MT_Buff[3][j]=MT_Buff[i%3][j];
  4670.         }
  4671.         plotrow(0,xc,xc+xs-1,i,MT_Buff[3]);
  4672.     }
  4673. }
  4674.  
  4675.  
  4676. /***********************************************************************
  4677. **
  4678. **
  4679. **
  4680. ***********************************************************************/
  4681.  
  4682. int fill_in(hue,val,buffer,todo,cx,cy,speed)
  4683.  
  4684. int todo[2][MAXDO];
  4685. int hue,val;
  4686. unsigned char *buffer;
  4687. int *cx,*cy,*speed;
  4688.  
  4689. {
  4690.     int i,j,k,m,n;
  4691.     int x=*cx,y=*cy,on=0;
  4692.     int lastup[2],lastdn[2];
  4693.     int fillval,cval;
  4694.  
  4695.     pix_loc(x,y,&x,&y,speed);
  4696.     *cx=x;*cy=y;
  4697.  
  4698.     fillval=getpt(hue,x,y);
  4699.     printf("starting at point %d,%d filling all %d pixels\n",x,y,fillval);
  4700.  
  4701.     on=check_point(hue,x,y,fillval,on,todo);
  4702.  
  4703.     do
  4704.     {
  4705.         lastup[0]=lastup[1]=lastdn[0]=lastdn[1]=-1;
  4706.         for(i=x;i<ScreenXs;i++)
  4707.         {
  4708.             if(getpt(hue,i,y)!=fillval)
  4709.                 break;
  4710.             plotpt(hue,i,y,val);
  4711.             on=check_point(hue,i,y,fillval,on,todo);
  4712.             if(getpt(hue,i,y-1)==fillval)
  4713.             {
  4714.                 lastup[0]=i;
  4715.                 lastup[1]=y-1;
  4716.             }
  4717.             if(getpt(hue,i,y+1)==fillval)
  4718.             {
  4719.                 lastdn[0]=i;
  4720.                 lastdn[1]=y+1;
  4721.             }
  4722.         }
  4723.         if(lastup[0]>=0&&on<MAXDO)
  4724.         {
  4725.             todo[0][on]=lastup[0];
  4726.             todo[1][on]=lastup[1];
  4727.             on+=1;
  4728.         }
  4729.         if(lastdn[0]>=0&&on<MAXDO)
  4730.         {
  4731.             todo[0][on]=lastdn[0];
  4732.             todo[1][on]=lastdn[1];
  4733.             on+=1;
  4734.         }
  4735.         lastup[0]=lastup[1]=lastdn[0]=lastdn[1]=-1;
  4736.         for(i=x-1;i>=0;i--)
  4737.         {
  4738.             if(getpt(hue,i,y)!=fillval)
  4739.                 break;
  4740.             plotpt(hue,i,y,val);
  4741.             on=check_point(hue,i,y,fillval,on,todo);
  4742.             if(y>0&&getpt(hue,i,y-1)==fillval)
  4743.             {
  4744.                 lastup[0]=i;
  4745.                 lastup[1]=y-1;
  4746.             }
  4747.             if(getpt(hue,i,y+1)==fillval)
  4748.             {
  4749.                 lastdn[0]=i;
  4750.                 lastdn[1]=y+1;
  4751.             }
  4752.         }
  4753.         if(lastup[0]>=0&&on<MAXDO)
  4754.         {
  4755.             todo[0][on]=lastup[0];
  4756.             todo[1][on]=lastup[1];
  4757.             on+=1;
  4758.         }
  4759.         if(lastdn[0]>=0&&on<MAXDO)
  4760.         {
  4761.             todo[0][on]=lastdn[0];
  4762.             todo[1][on]=lastdn[1];
  4763.             on+=1;
  4764.         }
  4765.         on=purge(hue,fillval,todo,on);
  4766.         do
  4767.         {
  4768.             on-=1;
  4769.             x=todo[0][on];
  4770.             y=todo[1][on];
  4771.         }while(getpt(hue,x,y)!=fillval&&on>0);
  4772.  
  4773.     }while(on>0);
  4774. }
  4775.  
  4776.  
  4777.  
  4778. /********************************************************************
  4779. **
  4780. **
  4781. **
  4782. ********************************************************************* */
  4783.  
  4784. int purge(hue,fillval,todo,on)
  4785.  
  4786. int hue,fillval,todo[2][MAXDO],on;
  4787.  
  4788. {
  4789.     int i,j,k;
  4790.  
  4791.     k=0;
  4792.     for(i=0;i<on;i++)
  4793.     {
  4794.         if(getpt(hue,todo[0][i],todo[1][i])==fillval)
  4795.         {
  4796.             todo[0][k]=todo[0][i];
  4797.             todo[1][k]=todo[1][i];
  4798.             k+=1;
  4799.         }        
  4800.     }
  4801.     return(k);
  4802. }
  4803.  
  4804.  
  4805.  
  4806.  
  4807.  
  4808. /********************************************************************
  4809. **
  4810. **
  4811. **
  4812. ********************************************************************* */
  4813.  
  4814. int check_point(hue,x,y,fillval,on,todo)
  4815.  
  4816. int hue,x,y,fillval,on,todo[2][MAXDO];
  4817.  
  4818. {
  4819.     if(on>=MAXDO)return(on);
  4820.  
  4821.     if(getpt(hue,x,y-1)==fillval&&y>0&&x>0&&x<ScreenXs-1)
  4822.     {
  4823.         if(getpt(hue,x-1,y-1)!=fillval||getpt(hue,x+1,y-1)!=fillval)
  4824.         {
  4825.             todo[0][on]=x;
  4826.             todo[1][on]=y-1;
  4827.             on+=1;
  4828.         }
  4829.     }
  4830.     if(on>=MAXDO)return(on);
  4831.  
  4832.     if(getpt(hue,x,y+1)==fillval&&y<ScreenYs-1&&x>0&&x<ScreenXs-1)
  4833.     {
  4834.         if(getpt(hue,x-1,y+1)!=fillval||getpt(hue,x+1,y+1)!=fillval)
  4835.         {
  4836.             todo[0][on]=x;
  4837.             todo[1][on]=y+1;
  4838.             on+=1;
  4839.         }
  4840.     }
  4841.     return(on);
  4842. }
  4843.  
  4844.  
  4845.  
  4846. /***********************************************************************
  4847. **
  4848. **
  4849. **
  4850. **
  4851. ************************************************************************/
  4852.  
  4853. int search_points(cx,cy,pixsize,outstring)
  4854.  
  4855. int *cx,*cy;
  4856. float pixsize;
  4857. char *outstring;
  4858.  
  4859. {
  4860.     int i,j,k;
  4861.     int ix,iy;
  4862.     double dcx=*cx,dcy=*cy,dx,dy,dist,mindist=1000000000,lat,lon;
  4863.     FILE *fploc;
  4864.     char string[STR_LEN],id[STR_LEN],id1[STR_LEN],*result;
  4865.     int numpoints=0;
  4866.  
  4867.     outstring[0]='\0';
  4868.     for(i=0;i<M.NumSymbol;i++)
  4869.     {
  4870.         if(PlaceFile[i].on==1&&
  4871.             pixsize>=PlaceFile[i].min_pix&&pixsize<PlaceFile[i].max_pix)
  4872.         {
  4873.             fploc=open_to_read_binary(PlaceFile[i].filename);
  4874.             if(fploc!=NULL)
  4875.             {
  4876.                 while((result=fgets(string,80,fploc))!=NULL&&strlen(string)>4)
  4877.                 {
  4878.                     string[strlen(string)-1]='\0';
  4879.                     if(sscanf(string,"%s%lf%lf%s",id1,&lat,&lon,id)!=4)
  4880.                     {
  4881.                         fclose(fploc);
  4882.                         break;    
  4883.                     }
  4884.                     ll_xy(&dx,&dy,lat,lon);
  4885.                     ix=dx,iy=dy;
  4886.                     if(ix>=0&&ix<ScreenXs&&iy>=0&&iy<ScreenYs&&
  4887.                         strlen(string)<STR_LEN)
  4888.                     {
  4889.                         dist=(dx-dcx)*(dx-dcx)+(dy-dcy)*(dy-dcy);
  4890.                         if(dist<mindist)
  4891.                         {
  4892.                             *cx=ix;*cy=iy;
  4893.                             mindist=dist;
  4894.                             strcpy(outstring,string);
  4895.                             numpoints+=1;
  4896.                         }
  4897.                     }
  4898.                 }
  4899.             }
  4900.             fclose(fploc);
  4901.         }
  4902.     }
  4903.     return(numpoints);
  4904. }
  4905.  
  4906.  
  4907.  
  4908.  
  4909. /***********************************************************************
  4910. **
  4911. **
  4912. **
  4913. **
  4914. ************************************************************************/
  4915.  
  4916. int set_back()
  4917.  
  4918. {
  4919.     int i,j,k;
  4920.     float r,g,b;
  4921.     float max=0.0;
  4922.  
  4923.     for(i=0;i<256;i++)
  4924.     {
  4925.         lutc[i].r=M.lut[i].r;
  4926.         lutc[i].g=M.lut[i].g;
  4927.         lutc[i].b=M.lut[i].b;
  4928.     }
  4929.     for(i=15;i<256;i++)
  4930.     {
  4931.         r=M.lut[i].r;
  4932.         g=M.lut[i].g;
  4933.         b=M.lut[i].b;
  4934.         if(r>max)max=r;
  4935.         if(g>max)max=g;
  4936.         if(b>max)max=b;
  4937.     }
  4938.     if(255.0/max<BackBright)
  4939.         BackBright=255.0/max;
  4940.     for(i=16;i<256;i++)
  4941.     {
  4942.         r=M.lut[i].r;
  4943.         g=M.lut[i].g;
  4944.         b=M.lut[i].b;
  4945.         lutc[i].r=r*BackBright;
  4946.         lutc[i].g=g*BackBright;
  4947.         lutc[i].b=b*BackBright;
  4948.     }
  4949.     WritePalette(lutc); 
  4950. }
  4951.  
  4952.  
  4953. /**************************************************************************
  4954. **
  4955. **
  4956. **
  4957. **
  4958. ***************************************************************************/
  4959.  
  4960. int plot_key(xc,yc,size)
  4961.  
  4962. int xc,yc,size;
  4963.  
  4964. {
  4965.     int i,j,k,l;
  4966.     int high=30/size,wide=0;
  4967.     int marg=6/size,val[2];
  4968.     unsigned char buffer[100];
  4969.     int x1=xc,y1=yc,color,twide;
  4970.  
  4971.     M.KeyPlotted=1;
  4972.     for(k=1;k<=M.Max_Fill;k++)
  4973.         if(strlen(M.Fill_Name[k])>wide)
  4974.             wide=strlen(M.Fill_Name[k]);
  4975.     wide=(wide+1)*15/size;
  4976.     twide=((M.Max_Fill-1)/(ScreenYs/high)+1)*wide;
  4977.     if(xc+twide>ScreenXs)
  4978.         x1=ScreenXs-twide;
  4979.     paint_box(0,M.Back,MT_Buff,x1,yc,twide,ScreenYs);
  4980.     for(i=1;i<=M.Max_Fill;i++)
  4981.     {    
  4982.         k=M.Fill_Order[i];
  4983.         if(VideoType=='X'||VideoType=='S'||VideoType=='Y')
  4984.         {
  4985.             val[0]=val[1]=k+16;
  4986.         }
  4987.         else
  4988.         {
  4989.             val[0]=M.Fill_Color[k][0];
  4990.             val[1]=M.Fill_Color[k][1];
  4991.         }
  4992.         for(j=0;j<wide+1;j++)
  4993.             buffer[j]=val[j%2];
  4994.         for(l=0;l<high;l++)
  4995.             plotrow(0,x1,x1+wide-1,l+y1,buffer+(l%2));
  4996.         color=M.Comp_Color[k+16];
  4997.         if(strlen(M.Fill_Name[k])>0)
  4998.             plot_font_h(color,x1+marg,y1+marg,
  4999.                 M.Fill_Name[k],size,Font);
  5000.         y1+=high;
  5001.         if(y1+high>ScreenYs)
  5002.         {
  5003.             y1=yc;
  5004.             x1+=wide;
  5005.         }
  5006.     }
  5007.     ScreenXs-=twide;
  5008. }
  5009.  
  5010.  
  5011. /********************************************************************
  5012. **
  5013. **    type  g -- grey all lut[] files
  5014. **            G -- grey only lut[]
  5015. **            i -- initial header map
  5016. **            r -- reset lut[] to lutc[]
  5017. **
  5018. **    iop == 1 don't print RGB etc.
  5019. **
  5020. **
  5021. ********************************************************************* */
  5022.  
  5023. void set_lut(type,iop)
  5024.  
  5025. char type;
  5026. int iop;
  5027.  
  5028. {
  5029.     int k,hue,brite,j,m,n;
  5030.     int color[3],h;
  5031.     double dbrite,dval;
  5032.     float val,minval,i,s,rgb[3];
  5033.     int c1,c2;
  5034.     long mindist,dist,r,g,b,r0,g0,b0;
  5035.  
  5036. /*
  5037.     if(type=='g')
  5038.     {
  5039.         M.lut[ 0].r=  0;
  5040.         M.lut[ 0].g=  0;
  5041.         M.lut[ 0].b=  0;
  5042.         M.lut[ 1].r= 46;
  5043.         M.lut[ 1].g= 46;
  5044.         M.lut[ 1].b= 46;
  5045.         M.lut[ 2].r=128;
  5046.         M.lut[ 2].g=128;
  5047.         M.lut[ 2].b=128;
  5048.         M.lut[ 3].r=255;
  5049.         M.lut[ 3].g=255;
  5050.         M.lut[ 3].b=255;
  5051.     }
  5052. */
  5053.     if(type=='c')
  5054.     {
  5055.         for(k=0;k<MAX_COLORS;k++)
  5056.         {        
  5057.             M.lut[ k].r=M.Color_Val[k][0];
  5058.             M.lut[ k].g=M.Color_Val[k][1];
  5059.             M.lut[ k].b=M.Color_Val[k][2];
  5060.         }
  5061.         for(k=MAX_COLORS;k<256;k++)
  5062.         {
  5063.             M.lut[ k].r=k;
  5064.             M.lut[ k].g=k;
  5065.             M.lut[ k].b=k;
  5066.         }
  5067.         if(M.Fill_In==1)
  5068.         {
  5069.             for(k=0;k<=M.Max_Fill;k++)
  5070.             {        
  5071.                 M.lut[k+16].r=(M.Color_Val[M.Fill_Color[k][0]][0]+
  5072.                                  M.Color_Val[M.Fill_Color[k][1]][0])/2;
  5073.                 M.lut[k+16].g=(M.Color_Val[M.Fill_Color[k][0]][1]+
  5074.                                  M.Color_Val[M.Fill_Color[k][1]][1])/2;
  5075.                 M.lut[k+16].b=(M.Color_Val[M.Fill_Color[k][0]][2]+
  5076.                                  M.Color_Val[M.Fill_Color[k][1]][2])/2;
  5077.             }
  5078.         }
  5079.         if(M.Fill_In==2)
  5080.         {
  5081.             for(k=1;k<=M.Max_Fill;k++)
  5082.             {        
  5083.                 r0=M.lut[k+16].r=M.Fill_Color_RGB[k][0];
  5084.                 g0=M.lut[k+16].g=M.Fill_Color_RGB[k][1];
  5085.                 b0=M.lut[k+16].b=M.Fill_Color_RGB[k][2];
  5086.                 mindist=16777216;
  5087.                 for(m=0;m<MAX_COLORS;m++)
  5088.                 {
  5089.                     for(n=m;n<MAX_COLORS;n++)
  5090.                     {
  5091.                         r=(long)(M.Color_Val[m][0]+M.Color_Val[n][0])/2;
  5092.                         g=(long)(M.Color_Val[m][1]+M.Color_Val[n][1])/2;
  5093.                         b=(long)(M.Color_Val[m][2]+M.Color_Val[n][2])/2;
  5094.                         dist=(r-r0)*(r-r0)+(g-g0)*(g-g0)+(b-b0)*(b-b0);
  5095.                         if(dist<mindist&&m!=M.Back&&n!=M.Back)
  5096.                         {
  5097.                             mindist=dist;
  5098.                             M.Fill_Color[k][0]=c1=m;
  5099.                             M.Fill_Color[k][1]=c2=n;
  5100.                         }
  5101.                     }
  5102.                 }
  5103.                 if(Fpout&&iop!=1)
  5104.                     fprintf(Fpout," %8s %8s %s\n",
  5105.                         M.Color_Name[c1],M.Color_Name[c2],M.Fill_Name[k]);
  5106.             }
  5107.         }
  5108.         if(M.Fill_In==3)
  5109.         {
  5110.             for(k=1;k<=M.Max_Fill;k++)
  5111.             {        
  5112.                 i=M.Fill_Color_IHS[k][0];
  5113.                 h=M.Fill_Color_IHS[k][1];
  5114.                 s=M.Fill_Color_IHS[k][2];
  5115.                 if(Fpout&&iop!=1)
  5116.                     fprintf(Fpout,"%3d %5.2f %3d %5.2f   ",k,i,h,s);
  5117.                 for(j=0;j<3;j++)
  5118.                 {
  5119.                     rgb[j]=MaxHues[h][j];
  5120.                     rgb[j]+=(255.0-rgb[j])*(1.0-s);
  5121.                     rgb[j]*=i;
  5122.                     if(rgb[j]<0.0)
  5123.                         rgb[j]=0.0;
  5124.                     if(rgb[j]>255.0)
  5125.                         rgb[j]=255.0;
  5126.                     if(Fpout&&iop!=1)
  5127.                         fprintf(Fpout,"%3.0f ",rgb[j]);
  5128.                 }
  5129.                 r0=M.lut[k+16].r=rgb[0];
  5130.                 g0=M.lut[k+16].g=rgb[1];
  5131.                 b0=M.lut[k+16].b=rgb[2];
  5132.                 mindist=16777216;
  5133.                 for(m=0;m<MAX_COLORS;m++)
  5134.                 {
  5135.                     for(n=m;n<MAX_COLORS;n++)
  5136.                     {
  5137.                         r=(long)(M.Color_Val[m][0]+M.Color_Val[n][0])/2;
  5138.                         g=(long)(M.Color_Val[m][1]+M.Color_Val[n][1])/2;
  5139.                         b=(long)(M.Color_Val[m][2]+M.Color_Val[n][2])/2;
  5140.                         dist=(r-r0)*(r-r0)+(g-g0)*(g-g0)+(b-b0)*(b-b0);
  5141.                         if(dist<mindist&&m!=M.Back&&n!=M.Back)
  5142.                         {
  5143.                             mindist=dist;
  5144.                             M.Fill_Color[k][0]=c1=m;
  5145.                             M.Fill_Color[k][1]=c2=n;
  5146.                         }
  5147.                     }
  5148.                 }
  5149.                 if(Fpout&&iop!=1)
  5150.                     fprintf(Fpout," %8s %8s %s\n",
  5151.                         M.Color_Name[c1],M.Color_Name[c2],M.Fill_Name[k]);
  5152.             }
  5153.         }
  5154.         for(k=0;k<256;k++)
  5155.         {
  5156.             if(M.lut[k].r>128||M.lut[k].g>128||M.lut[k].b>160)
  5157.                 M.Comp_Color[k]=M.Black;
  5158.             else
  5159.                 M.Comp_Color[k]=M.White;
  5160.         }
  5161.     }
  5162.     WritePalette(M.lut); 
  5163. }
  5164.  
  5165.  
  5166.